I have two dictionaries and I want to compare them. I want to ignore case and only return false if they have different values. Here is my code.
var dic1 = new Dictionary<String, String>(StringComparer.CurrentCultureIgnoreCase);
dic1.Add("Key 2", "Value 2");
dic1.Add("Key 1", "Value 1");
var dic2 = new Dictionary<String, String>(StringComparer.CurrentCultureIgnoreCase);
dic2.Add("Key 1", "Value 1");
dic2.Add("Key 2", "Value 2");
var areEqual = dic1.OrderBy(r => r.Key).SequenceEqual(dic2.OrderBy(r => r.Key));
Console.WriteLine(areEqual);
As you can see I am using the SequenceEqual method of the dictionary class to compare the two dictionaries. I have ordered them by key so that the result is not false if the key position is different. The problem I cant seem to figure out is how to ignore the case in key and values and return false only if values are different. In my case value 1 and VALUE 1 are both equal and the result should be true. That is not my case here.