TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C# Coding Standard

Rule:  7@503

Synopsis:If you implement one of operator==(), the Equals method or GetHashCode(), implement all three
Severity Level:1
Category:Object oriented


If your 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 null argument.

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.