List<List<int>> li = new List<List<int>>() { new List<int>{0,1,2},new List<int>{3,4,5},new List<int>{6,7,8}};
计算出li中,即共有多少个阿拉伯数字,用LINQ

解决方案 »

  1.   

    var count = ( from a in li select a.Count ).Sum()  ;
      

  2.   

    int numberCount = li.SelectMany(o => o).Distinct(o => o).Count();
      

  3.   

    int numberCount = li.SelectMany(o => o).Distinct().Count();
      

  4.   

    sorry,早上不是睡得太醒,Distinct方法不用带参数:int numberCount = li.SelectMany(o => o).Distinct().Count();
      

  5.   

    li.SelectMany(o => o).Count();
      

  6.   


    //去除重复数:
    int count= li.SelectMany(i => i).Distinct().Count();
    Console.Write(count);//统计所有数:
    int count= li.SelectMany(i => i).Count();
    Console.Write(count);
      

  7.   

    不去重的话就不要SelectMany了,直接
    li.Sum(x => x.Count)