Get sum of the value from list using linq?

后端 未结 4 1214
-上瘾入骨i
-上瘾入骨i 2020-12-31 06:57

I am trying to get the sum of the value from list of list using linq ?my data is as below code

        List> allData = new List<         


        
4条回答
  •  星月不相逢
    2020-12-31 07:35

    var grouped = allData.GroupBy(x => x[0])
                         .Select(g => new
                         {
                             Name = g.Key,
                             Sum = g.Sum(x => int.Parse(x[2]))
                         });
    

    It will return an anonymous type instance for each group, with two properties: Name with your grouping key and Sum with sum of marks.

提交回复
热议问题