C#、.NET 4.5 链接
我有一个 Persons 集合。每个人都有一个国家,这个国家有一个正确的名字。
我需要打印出人数结果显示:
Canada 45
USA 445
Holland 4
不确定如何。
Source object is like this, fairly simple:
Person.Country.Name
最佳答案
personList.GroupBy(x => x.Country.Name)
.Select(x => new { CountryName = x.Key, Count = x.Count() });
关于c# - 按总数分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22427346/