0
我有一個字典列表,如:C#從列表創建字典<Dictionary>
dic1.Add("A_key1","A_val11"); dic1.Add("B_key1","B_val11")
dic1.Add("C","C"); dic1.Add("D","D");
dic2.Add("A_key1","A_val21"); dic1.Add("B_key1","B_val21");
dic2.Add("C","C"); dic1.Add("D","D");
dic2.Add("A_key2","A_val22"); dic1.Add("B_key2","B_val22");
dic2.Add("A_key3","A_val23"); dic1.Add("B_key3","B_val23");
List<Dictionary<string,string>> tempList = new List<Dictionary<string,string>>{dic1, dic2};
我需要從tempList創建字典遵循的規則:關鍵= 「A_Key的*」 值,VAL =「B_key * 「來自列表中所有原始字典的價值。 例如,在上例中:
expectDic = {("A_val11","B_val11"),
("A_val21","A_val21"),
("A_val22","A_val22"),
("A_val23","A_val23")}
我可以用Linq解決嗎?
'SelectMany'和'ToDictionary'的組合可能會訣竅 –
是否會只有2個字典?那麼這兩個字典中沒有匹配鍵的項目呢? – sachin
什麼是'dic2'? – Maarten