Get sum of the value from list using linq?

后端 未结 4 1188
-上瘾入骨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:26

    Not sure if you want to get the sum of every group or the total. If it's the total then this should do the trick

    var sum = allData.Sum(x => Int32.Parse(x[2]));
    

    If it's per key then try the following

    var all = allData
      .GroupBy(x => x[0])
      .Select(x => x.Sum(y => Int32.Parse(y[2]));
    

提交回复
热议问题