我目前有2個詞典,其中包含ard 30,000keys。使用foreach和.contains比較兩個詞典以找到唯一和非唯一數據的最快方法
我目前使用兩個foreach循環來查找dict1中的唯一鍵。然後我將dict2中的唯一鍵寫入另一個字典(3)。
如果鍵匹配我執行檢查,看看值是否相同。如果它們不一樣,就打印出來。
使用foreach是否更好,它似乎影響性能。有沒有其他更快的解決方案或內置函數? Ir shd我嘗試了dict.contains方法。
Dict1 Dict2
Keys Values Keys Values
S0111 00000 S0000 00010
S0000 00010 S0020 00015
S0020 00015 S0040 00150
S0040 00200 S0050 00250
foreach (KeyValuePair<string, string> sourceRow in sourceData)
{
foreach (KeyValuePair<string, string> dumpRow in dumpData)
{
// A in C, skip
if (sourceRow.Key == dumpRow.Key)
{
Is_Unique_Address = false;
if (sourceRow.Value != dumpRow.Value)
{
Data_Mismatch_Criteria(sourceRow.Key, sourceRow.Value, dumpRow.Key, dumpRow.Value);
}
}
}
}
什麼你通過尋找獨特的按鍵的意思是,在字典中的鍵總是唯一的! – sachin
目前尚不清楚。字典中的所有密鑰始終是唯一的。在此提供代碼示例。 –
我認爲在這種情況下是唯一的手段:在字典中,但在其他字典中的鍵 – DarkSquirrel42