i have 2 dictionaries , want compare against each other , of type dictionary>
i tried using foreach loop won't work desired.what's best way go it?
foreach (keyvaluepair<string, dictionary<string, object>> entry1 in dict1) { foreach (keyvaluepair<string, dictionary<string, object>> entry2 in dict2) { if (entry1.key = entry2.key) { if (entry1.value["number"]==entry2.value["number"]) { console.writeline("comparison successful") } } } }
public static boolean comparedictionary(dictionary<string, object> d1, dictionary<string, object> d2) { if (d1 == null && d2 == null) return true; else if (d1 == null || d2 == null) return false; if (d1.count != d2.count) return false; if (d1.keys.except(d2.keys).any()) return false; if (d2.keys.except(d1.keys).any()) return false; foreach (string key in d1.keys) { if (!d2.containskey(key)) return false; if (d1[key] != d2[key]) return false; } return true; }
Comments
Post a Comment