List Contains always returns false C#
I have a class for which I have implemented a custom hashCode() and equals(Object) method using the Eclipse method generator. Each object of the class has a String field called mUid which should be unique and is enough to determine equality. The overridden methods look like this: But for some reason, when I compare two objects of my class, it always returns false. I've stepped through the code with a debugger and can determine that the mUid strings are the same. But my equals(Object) method always returns false at the line if (!mUid.equals(other.mUid)) {return false;}. This means the String equals() method is saying the strings are not equal. But, in the debugger I can see that even their hashcodes are equal. Here is a debugging screenshot: Can anyone please explain what is happening? Thanks.Update: It works!I should point out that I am not calling the equals(...) method directly, but rather from Listlist.contains(DataSource). It turns out that if I step through the equals(Object) code, it shows me that it returns false for comparing every object in the list (even if there is a match). But it seems the List.contains() method returns the right value (true or false) anyway. Don't know why this is, but it works. I had an extra semicolon after the if(list.contains(dataSource)); so I could not rightly see that contains() was working fine. Thanks for your help everyone. |