C# Linq Group By 对多列进行分组
public class ConsolidatedChild
{
public string School { get; set; }
public string Friend { get; set; }
public string FavoriteColor { get; set; }
public List<Child> Children { get; set; }
}
public class Child
{
public string School { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Friend { get; set; }
public string Mother { get; set; }
public string FavoriteColor { get; set; }
}
鉴于上面的两个类,我想使用 LINQ 从列表中创建一个列表,按 School、Friend 和 favoriteColor 属性分组。这可以用 LINQ 实现吗?
请忽略这些属性,编写代码只是为了帮助解决问题。
public class ConsolidatedChild
{
public string School { get; set; }
public string Friend { get; set; }
public string FavoriteColor { get; set; }
public List<Child> Children { get; set; }
}
public class Child
{
public string School { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Friend { get; set; }
public string Mother { get; set; }
public string FavoriteColor { get; set; }
}
Given the two classes above, I would like to use LINQ to create a List from the List, grouped by the School, Friend and FavoriteColor properties. Is this possible with LINQ?
Please ignore the properties, the code has been written just to help with the question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
给定一个列表:
查询将如下所示:
测试代码:
结果:
Given a list:
The query would look like:
Test code:
Result: