I have a List<Object> and object has many fields one of these is LastName. How would i get a list of distinct LastNames and a Count of each time that LastName occured.
For Example
Jones, Smith, Anderson, Colins, Smith, Jones
Would return list
Jones, 2
Smith, 2
Anderson, 1
Colins, 1
Update I have managed to achieve the below but in stead of var results I would like a List of Object type Name, Count. Is this possible?
var results = mylist.GroupBy(n=>n.LastName).Select(g=> new{ Name = g.First().LastName, Count = g.Count()}).ToList();
Thank you for your assistance.