C# linq group by
c#, linq
Solution
from p in names
group p by p.Name into g
order by g.Key
select new { Name = g.Key, Amount = g.Sum(o => o.Amount) }
Problem
How do I count, group and sort the following list based on a persons money with linq? ``` Person[] names = { new Person{ Name = "Harris", Money = 100 }, new Person{ Name = "David", Money = 100 }, new Person{Name = "Harris", Money = 150}, new Person{Name = "Mike", Money = 100}, new Person{Name = "Mike", Money = 30}, new Person{Name = "Mike", Money = 20} }; ``` The result would return: ``` Harris 250 Mike 150 David 100 ```