我有兩個不同長度的字典列表。兩個字典中的鍵都是相同的,值可能不一樣。僅通過特定鍵的值相交字典的兩個列表C#
var A = List<Dictionary<string, object>>();
var B = List<Dictionary<string, object>>();
我想交叉的A和B基於它們包含的字典對象中的3個鍵的值。
對於例如:
var dict = new Dictionary<string,object>{{"W",val1},{"X",val2},{"Y",val3},{"Z",val4}}
字典類似於上述被包含在列表中A和B有用於VAL1,VAL2,VAL3,VAL4變化值。如果鍵W,X,Y的值相等,我想交叉A和B,但我不關心Z中交點的值。有沒有辦法實現這個優雅?
用一個例子闡述:
A.add(new Dictionary<string,object>{{"W",123},{"X",456},{"Y",789},{"Z",103}});
A.add(new Dictionary<string,object>{{"W",124},{"X",456},{"Y",789},{"Z",893}});
A.add(new Dictionary<string,object>{{"W",123},{"X",456},{"Y",789},{"Z",134}});
B.add(new Dictionary<string,object>{{"W",123},{"X",456},{"Y",789},{"Z",900}});
B.add(new Dictionary<string,object>{{"W",124},{"X",456},{"Y",789},{"Z",893}});
B.add(new Dictionary<string,object>{{"W",212},{"X",321},{"Y",789},{"Z",134}});
如果我做A.intersect(B),我想獲得以下列表後面,
{"W",123},{"X",456},{"Y",789},{"Z",103}
{"W",123},{"X",456},{"Y",789},{"Z",900}
{"W",124},{"X",456},{"Y",789},{"Z",893}
我不知道我理解的問題。你能舉一個例子說明在這種情況下會有什麼樣的結果嗎? – MikeTheLiar
等什麼?你有兩本詞典清單? –
交叉點是什麼意思? –