And moreover, why does your example works and what paradigm have you violated to achieve the result?
The answer could be rather simple, but sometimes (again, for value types) it is kinda weird.
To find the answer, let's go down to Object.Equals(a,b) implementation:
public static bool Equals(object objA, object objB)
{
return ((objA == objB) || (((objA != null) && (objB != null)) && objA.Equals(objB)));
}
The operator == is defined as ReferenceEqual(), so reference typed object before any comparison would be compared by reference. So the simplest answer is to override Equals() method to always return false.
There is three simple paradigm for the Equals() method:
- a.Equals(b) == b.Equals(a)
- a.Equals(a) == true
- If a.Equals(b) and b.Equals(c), then a.Equals(c)
No comments:
Post a Comment