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 Value
- Alabama AB 9
- Alabama AB 4
- Arizona AZ 5
- Texas TX 6
- Texas TX 15
- California CA 14
- California CA 11
- California CA 2
Considering the above List<ValueLabels>
object (each ValueLabel object will have set of State, Label and value), I should generate another list which contains below information.
- Alabama AB 13
- Arizona AZ 5
- Texas TX 21
- California CA 27
That mean, eventually, I should get a unique records based on State property and value property should be sum of all duplicate entries based on State property.
I have used ListObj.DistinctBy(p => p.State).ToList()
function with lambda expression but I could not add the values to gether.
Can anyone help me in achieving the above? Please let me know if further information is needed.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…