这个问题在这里已有答案:
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从List创建一个List,按School,Friend和FavoriteColor属性分组 . LINQ可以实现吗?
请忽略属性,代码编写只是为了帮助解决问题 .
2 回答
简单:
给出一个清单:
查询看起来像:
测试代码:
结果: