我想扁平化(取消组合)我的字典 - 并尝试如果它可以由Linq完成。Dictionary <something,List <>> flatten(ungroup)以列表的东西和列表中的元素 - C#
样品输入:
Dictionary<int, List<string>> dict = new Dictionary<int, System.Collections.Generic.List<string>>();
dict.Add(0, new List<string>() { "a", "b" });
dict.Add(1, new List<string>() { "c", "d"});
我想要实现的是以下元素的列表:
当然0A
0B
1C
1D
这是可以做到的:
List<string> output = new List<string>();
foreach (var element in dict)
{
foreach (var valuesElement in element.Value)
{
output.Add(element.Key + valuesElement);
}
}
我只是在寻找是否有任何“聪明” LINQ建设来实现它。