|Synopsis:||If you implement one of |
Equals method or
GetHashCode(), implement all three
Equals method can throw an exception, this may cause problems if objects of that type are put into a container. Do consider to return
false for a
The msdn guidelines [MS Design] recommend to return
false rather than throwing an exception when two incomparable objects, say the proverbial apples and oranges, are compared. Since this approach sacrifices the last remnants of type-safety, this recommendation has been weakened.
In very rare cases it can be meaningful to override
GetHashCode() without implementing the other two.
There is no need to implement the
operator==() for reference types because a default implementation is available.