本帖最后由 imsasuke 于 2010-10-28 20:15:58 编辑

解决方案 »

  1.   

    var result=from q in list where q==null select q;
      

  2.   

    加个if 判断是否为空啊foreach (var item in list)
    {
       if (item != null)
           Console.WriteLine(item);
    }
      

  3.   

    这样的话效率很低 因为 每个list的item都要去遍历, 我 想要效率高些的 ,怎么弄?
      

  4.   


    string[] list=new list[6];
    bool readSucceed = false;
    while(reader.Read())
    {
        readSucceed = true;
        for(int i=0;i<6;i++)
        {
           list[i]=reader[i].Tostring();
        }
    }
      

  5.   

    不 能这样,因为我的list是返回到另外一个页面的,所以现在是 当当就 问题,怎么判断list[i]为null这个问题做处理...
      

  6.   

    还是用List<String>更好:List<string> data = new List<string>();
    while(reader.Read())
    {
        for(int i=0; i<6; i++)
        {
           data.Add(reader[i].Tostring());
        }
    }if (data.Count > 0)
       // 有值
    else
       // 没值
      

  7.   


    这个很简单, 再加上一句if (!readSucceed)
      list = null;
      

  8.   

    string[] list=new list[6];
    string str="";
    for(int i=0;i<6;i++)
        {
       str+=list[i];
       }
    if(str!=null){
    //操作
    }
      

  9.   

    不要 改变我的方法啊,我 的方法 返回 list[]数组已经是固定了 的 ,现在就是判断list数组的值全为空。
    怎么做?
      

  10.   


    然后怎么判断这个list 是 null啊?
      

  11.   

    如果定死是6个,那直接写死最快了。
    if(List[0]==null||List[1]==null||List[2]==null||List[3]==null||List[4]==null||List[5]==null)
    {
        return;
    }
      

  12.   

    换用 List<string> ,而不是 string[]bool empty = list.TrueForAll(x=>x==null);
      

  13.   

    Sorry,换用 List<string> 之后,读不成功的时候,其元素个数为 0。string[] 上也可以用 trueforall,调用方法略有不同:bool empty = Array.TrueForAll(list, x=>x==null);
      

  14.   

    string[] list = new string[] { null, null, "a" };            var l = from s in list select s;            Console.WriteLine(l.All(o => o == null));//False
      

  15.   

    string[] list = new string[] { null, null, null }; 返回True
    All()就是说全满足就返回True