考虑以下对象:
public class Address { public string city; public string state; public string country; }
Run Code Online (Sandbox Code Playgroud)
如果我有一个地址列表,我将如何使用LINQ获取城市,州和国家匹配的计数列表.
所以我的结果看起来像这样:
谢谢!
比Marc的答案更进了一步(他在我发布之前编辑过!).大声笑
var qry = from addr in addresses
group addr by new { addr.city, addr.state, addr.country } into grp
select new
{
city = grp.Key.city,
state = grp.Key.state,
country = grp.Key.country,
count = grp.Count(),
};
Run Code Online (Sandbox Code Playgroud)