List Distinct entries based on property and sum of duplicates

前端 未结 3 1190
感动是毒
感动是毒 2020-12-21 17:49

Im wondering I may be asking a simple question, but trying to get a elegant solution. I have a situation where below are the rows

State Label <

3条回答
  •  心在旅途
    2020-12-21 18:30

    Not tested, but this should work.

    var newList = list.GroupBy(x=> new {x.State , x.Label })
                      .Select(x=> new YourClass(x.Key.State, x.Key.Label, x.Sum(x=>x.Value) ))
                      .ToList();
    

提交回复
热议问题