Compare Generics Dictionary

I've some generics dictionary objects, I want to compare if they contain the same key and value.

Dictionary<string, string> a = new Dictionary<string, string>();
a.Add("A", "001");
a.Add("B", "002");

Dictionary<string, string> b = new Dictionary<string, string>();
b.Add("A", "001");
b.Add("B", "002");

Dictionary<string, string> c = new Dictionary<string, string>();
b.Add("A", "001");
b.Add("C", "002");

I want to compare the above objects, a and b are treated to be equal because they contain the same key and value, but c is different from them. How can I do it

Thank you very much!!



Answer this question

Compare Generics Dictionary

  • kishore_golla

    Hi!

    You can check that elements counts in collections are equal, then you can iterate one dictionary and compare with another.


  • Compare Generics Dictionary