次のようなコードがあります。
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でこれを行う方法はありますか?
ありがとう。