【发布时间】:2018-12-11 14:44:24
【问题描述】:
我有IEnumerable<GroupResult<T>>,其中GroupResult<T> 如下:
public class GroupResult<T>
{
public string Key { get; set; }
public IEnumerable<T> Items { get; set; }
}
假设集合如下所示:
{
Key: "1",
Items: { "A", "B" }
}
{
Key: "1",
Items: { "C", "D" }
}
{
Key: "2",
Items: { "E", "F" }
}
我可以执行什么操作来获得以下信息:
{
Key: "1",
Items: { "A", "B", "C", "D" }
}
{
Key: "2",
Items: { "E", "F" }
}
【问题讨论】:
-
到目前为止你尝试了什么?
-
您可以使用
Dictionary<string,IEnumerable<T>>,而不是使用IEnumerable<GroupResult<T>>,这样可以首先防止重复键。
标签: c# linq ienumerable