怎么用while条件表达式来表示一个list集合内所有元素为空字符串?

解决方案 »

  1.   

    while (list.Count != 0)
    {
        ...
    }
      

  2.   

    while (list!=null&&list.Count>0) 
    {}
    每个值string.isnullorempty
      

  3.   

    请看清楚问题,我刚刚有个地方说错了~
    我是要表示一个list集合内不是所有元素都为空字符串,但这个集合内是有元素! 
      

  4.   

    int iCount = 0,i = 0;
    while(iCount <= list.Count)
    {
      i++;
      iCount ++;
      if([i].toString() = "")
      {
        return
       }
    }
      

  5.   

    请看清楚问题,我刚刚有个地方说错了~
    我是要表示一个list集合内不是所有元素都为空字符串,但这个集合内是有元素!
    [/Quote]
    用个bool值做标志,默认为false,如果有不为空的字符串就把这个bool值设置成true并退出,在循环外判断这个bool值就可以了吧。
      

  6.   

    请看清楚问题,我刚刚有个地方说错了~
    我是要表示一个list集合内不是所有元素都为空字符串,但这个集合内是有元素!
    [/Quote]
    bool isEmpty = true;
    int i = 0;
    while (i > list.Count)
        if (list[i] != "") { isEmpty = false; return; }
    // 此时 isEmpty 就是你要的。
      

  7.   

    不过以下代码更简单:
    bool isAllEmpty = true; 
    list.ForEach(s => { (if s != "") isAllEmpty = false });