Вы можете сделать это так:
using System.Linq;
using System.Collections.Generic;
public static class DictionaryExtensions {
public static bool IsEqualTo(this Dictionary<string, Tuple<string, string>> dict1, Dictionary<string, Tuple<string, string>> dict2) {
if (!Enumerable.SequenceEqual(dict1.Keys.OrderBy(x => x), dict2.Keys.OrderBy(x => x))) {
return false;
}
foreach(var kvp in dict1) {
var corresponding = dict2[kvp.Key];
if (kvp.Value.Item1 != corresponding.Item1 || kvp.Value.Item2 != corresponding.Item2) {
return false;
}
}
return true;
}
}
А потом использовать:
Dictionary<string, Tuple<string, string>> dict1= new Dictionary<string, Tuple<string, string>>();
Dictionary<string, Tuple<string, string>> dict2= new Dictionary<string, Tuple<string, string>>();
Console.WriteLine(dict1.IsEqualTo(dict2)); // True
dict1["a"] = new Tuple<string, string>("a", "b");
dict2["a"] = new Tuple<string, string>("a", "b");
Console.WriteLine(dict1.IsEqualTo(dict2)); // True
dict2["a"] = new Tuple<string, string>("a", "b2");
Console.WriteLine(dict1.IsEqualTo(dict2)); // False
dict2["a"] = new Tuple<string, string>("a", "b");
dict2["b"] = new Tuple<string, string>("a", "b2");
Console.WriteLine(dict1.IsEqualTo(dict2)); // False
Обновить Спасибо Aluan Haddad за указание на проблему сортировки.