目前excel表结构是 A  10B   5C   6A   5B   5C 14到内存表应该是 A 15B 10C 20请问如何操作

解决方案 »

  1.   

     IList<Test> tlist = new List<Test>();
                tlist.Add(new Test() {Key="A",Value=15 });
                tlist.Add(new Test() { Key = "B", Value = 10 });
                tlist.Add(new Test() { Key = "A", Value = 5 });
                tlist.Add(new Test() { Key = "B", Value = 6 });
                var rst = (from t in tlist
                          group t by t.Key
                          into tt
                          select new {k= tt.Key, r=tt.Sum(x => x.Value) }).ToList();
    这种效果?
      

  2.   


    这是linq? 应该是这种效果吧 但我不想用linq 想直接用datatable操作
      

  3.   

      List<string> list = new List<string>();
                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {                    if (!list.Contains(i.ToString()))
                        {
                            dt.Rows.Add();
                            list.Add(i.ToString());
                            dt.Rows[0][1] = j;
                        }
                        else
                        {
                            continue;
                        }
                  
                    }
    兩個表循環一下啊,A,b,c用list保存
      

  4.   

    https://www.cnblogs.com/sydeveloper/archive/2013/03/29/2988669.html
    linq to dataTable了解一下
      

  5.   

    asenumerable() 一下即可https://blog.csdn.net/zx13525079024/article/details/7277425