I have a question that’s similar to yesterday’s question.
I’ve got this List<object[]>
List<object[]> olst = new List<object[]>();
olst.Add(new object[] { "AA1", "X", 1, 3.50 });
olst.Add(new object[] { "AA2", "Y", 2, 5.20 });
olst.Add(new object[] { "AA2", "Y", 1, 3.50 });
olst.Add(new object[] { "AA1", "X", 1, 3.20 });
olst.Add(new object[] { "AA1", "Y", 2, 5.30 });
I need to produce List<object[]> to hold this:
"AA1", "X", 2, 6.70
"AA2", "Y", 3, 8.70
"AA1", "Y", 2, 5.30
In other words, I need to group olst by the 1st and 2nd elements of each object[] and sum 3rd and 4th.
I could use a for loop, but I was hoping someone could help me using lambda expressions and/or linq to accomplish this.
You need to group by an anonymous type, then sum the third and fourth columns: