I have two Generic Dictionaries.Both have same keys.But values can be different.I want to compare 2nd dictionary with 1st dictionary .If there are differences between values
If you've already checked that the keys are the same, you can just use:
var dict3 = dict2.Where(entry => dict1[entry.Key] != entry.Value)
.ToDictionary(entry => entry.Key, entry => entry.Value);
To explain, this will:
dict2dict1 and filter out any entries where the two values are the samedict1 value is different) by taking the key and value from each pair just as they appear in dict2.Note that this avoids relying on the equality of KeyValuePairToDictionary, too.)