On Wed, 17 Sep 2008 11:55:05 -0700, Luigi <ci****************@inwind.it>
wrote:
Hi all,
I have two Dictionary exactly the same, but if I try to verify this
likeness, I get false, like this code:
Dictionary<int,stringTestA = new Dictionary<int,string>();
Dictionary<int,stringTestB = new Dictionary<int,string>();
TestA.Add(1, "TestString");
TestB.Add(1, "TestString");
bool result = (TestA == TestB); // returns "false"
Just for the record, that fails because the Dictionary class doesn't
provide an operator == overload. It also doesn't override
Object.Equals(), so you couldn't use that as a workaround either.
If you had been using C# 3.0 with .NET 3.5, you would have been able to
use the Enumerable.SequenceEqual() extension method:
bool result = TestA.SequenceEqual(TestB);
But if you're stuck with C# 2.0, I think you'll have to essentially
implement the iterative comparison yourself. I'm not aware of a built-in
implementation of something like this for the Dictionary class.
Pete