I have an object that looks like this:
Notice
{
string Name,
string Address
}
In a List
I want to output A
A variation on Leniel's answer, using a different overload of GroupBy:
var query = notices.GroupBy(n => n.Name,
(key, values) => new { Notice = key, Count = values.Count() });
Basically it just elides the Select
call.
var noticesGrouped = notices.GroupBy(n => n.Name).
Select(group =>
new
{
NoticeName = group.Key,
Notices = group.ToList(),
Count = group.Count()
});