我有一个简单的业务对象:
Crime
Date
PersonsInvolved
我需要每个月的 PersonsInvolved 总人数列表。数据是 1 年的,因此不需要考虑年份。
Jan 5
Feb 3
Mar 5
等等
如果我有这样的内存集合,在 Linq 中是如何完成的:
List<Crime>() crimes;
最佳答案
crimes.GroupBy(c => c.Date.Month)
.Select(g => new { Month = g.Key, Count = g.Count() });
关于c# - Linq:按月汇总组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8719469/