C# 在C中使用LINQ进行字典操作#
我有一本像这样的字典C# 在C中使用LINQ进行字典操作#,c#,linq,dictionary,lambda,C#,Linq,Dictionary,Lambda,我有一本像这样的字典 Dictionary<String, List<String>> MyDict = new Dictionary<string, List<string>> { {"One",new List<String>{"A","B","C"}}, {"Two",new List<String>{"A","C","D"}} }; 有谁能建议我用LINQ或LAMBDA表达式来实现这一点吗 var
Dictionary<String, List<String>> MyDict = new Dictionary<string, List<string>>
{
{"One",new List<String>{"A","B","C"}},
{"Two",new List<String>{"A","C","D"}}
};
有谁能建议我用LINQ或LAMBDA表达式来实现这一点吗
var items=MyDict.Values.SelectMany(x=>x).Distinct().ToList();
或另一种选择:
var items = (from pair in MyDict
from s in pair.Value
select s).Distinct().ToList();
哦,你赢了我:p。Linq问题总是很有趣的。
var items = (from pair in MyDict
from s in pair.Value
select s).Distinct().ToList();