我有类似这样的代码:
var dict = new Dictionary<string, IList<string>>();
dict.Add("A", new List<string>{"1","2","3"});
dict.Add("B", new List<string>{"2","4"});
dict.Add("C", new List<string>{"3","5","7"});
dict.Add("D", new List<string>{"8","5","7", "2"});
var categories = new List<string>{"A", "B"};
//This gives me categories and their items matching the category list
var result = dict.Where(x => categories.Contains(x.Key));
键值
A 1、2、3
B 2、4
我想得到的是:
A 2
B 2
所以键和两个列表中的值。有没有办法在 LINQ 中做到这一点?
谢谢。