![](/img/trans.png)
[英]How to compare two List of Dictionary values and put new key into dictionary?
[英]How to compare list values in a dictionary
如何比較Dictionary<String, List<String>>
字典中的值?
如果字典中的所有值都相同,那么做一些事情。 別的什么都不做。
謝謝
如果要比較 Dictionary 的鍵,則:
var dict1 = new Dictionary<string, List<string>>();
var dict2 = new Dictionary<string, List<string>>();
// something..
if (dict1.Keys.SequenceEqual(dict2.Keys))
{
// your code
}
如果要比較 Dictionary 的值,則:
var dict1 = new Dictionary<string, List<string>>();
var dict2 = new Dictionary<string, List<string>>();
// something..
var d1Keys = dict1.Keys.ToList();
var result = d1Keys
.All(key => dict2.ContainsKey(key) && dict1[key].SequenceEqual(dict2[key]));
// result == true, if equals
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.