EntryEquals

public static bool EntryEquals<TKey,TValue>(this IDictionary<TKey, TValue> dict, IDictionary<TKey,TValue> other) where TValue : class
{
	foreach(KeyValuePair<TKey,TValue> kvp in dict)
	{
		if (other.ContainsKey (kvp.Key))
		{
			TValue otherValue = other[kvp.Key];
			if (!kvp.Value.Equals(otherValue)) return false;
		} else
		{
			return false;
		}
	}
	return true;
}
Example:
Dictionary<int, string> d = new Dictionary<int, string> {{1,"one"}, {2,"two"}, {3,"three"}};
Dictionary<int, string> d2 = new Dictionary<int, string> { { 3, "three" }, { 1, "one" }, { 2, "two" } };

Debug.Assert(d.EntryEquals (d2));

Description

Extension method for comparing dictionaries by elements (key pair values)

Details

Double click on the code to select all.

 

;