我想展平(取消分组)我的字典 - 并尝试是否可以由 Linq 完成。
样本输入:
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
1天
当然可以通过以下方式完成:
List<string> output = new List<string>();
foreach (var element in dict)
{
foreach (var valuesElement in element.Value)
{
output.Add(element.Key + valuesElement);
}
}
我只是在寻找是否有任何“聪明”的 linq 结构来实现它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句