【发布时间】:2014-06-25 18:09:29
【问题描述】:
好的,我有一个列表,我想将具有相同名字的对象合并为一个,并将兄弟姐妹添加到其他兄弟姐妹列表中。
public class People
{
string Name {get; set;}
List<string> siblings {get; set;}
}
现在我有一个看起来像
的列表 List<People> list3 = new List<People>
{
new People
{
name = "Chris",
siblings = {"Richard"}
},
new People
{
name = "Billy",
siblings = {"Thomas"}
},
new People
{
name = "Bob",
siblings = {"Charles"}
},
new People
{
name = "Chris",
siblings = {"Simon"}
}
}
现在我希望它变成:
List<People> list3 = new List<People>
{
new People
{
name = "Chris",
siblings = {"Richard", "Simon"}
},
new People
{
name = "Billy",
siblings = {"Thomas"}
},
new People
{
name = "Bob",
siblings = {"Charles"}
}
}
【问题讨论】:
-
您的代码首先在属性名称和兄弟姐妹初始化上有错误。
-
@RyanEmerle 刚刚尝试使用 select 进行 selectMany