I need to calculate the Aggregate of a certain property from an object list by grouping the objects based on another property.. For example, I have a list of 5 objects as below:
list<cls> Objlist = new list<cls>();
Obj1.Name="earth";
Obj1.Value = 10;
objlist.add(Obj1);
Obj2.Name="sun";
Obj2.value = 15;
objlist.add(Obj2);
Obj3.Name = "earth";
Obj3.Value = 25;
objlist.add(Obj3);
Obj4.Name = "earth";
Obj4.Value = 35;
objlist.add(Obj4);
Obj5.Name="sun";
Obj5.value = 50;
objlist.add(Obj5);
What I need is another list to have the avg value of earth and sun objects.. How this can be accomplished using LINQ?
Averageis what you need from LINQ, useGroupByto group byNamefirst: