Counting Using Group By Linq

后端 未结 2 965
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 02:02

I have an object that looks like this:

Notice 
{
    string Name,
    string Address 
}

In a List I want to output A

2条回答
  •  野的像风
    2021-02-05 03:06

    var noticesGrouped = notices.GroupBy(n => n.Name).
                         Select(group =>
                             new
                             {
                                 NoticeName = group.Key,
                                 Notices = group.ToList(),
                                 Count = group.Count()
                             });
    

提交回复
热议问题