This rule is Obsolete | |
Synopsis: | Reference types should NOT override the equality operators ('== ' and '!= ') |
Language: | C# |
Severity Level: | 1 |
Category: | Object oriented |
Description: |
There's a very simple reason for this coding rule:
== ' and '!= ') on reference types check for reference equality ! So overriding this behavior introduces counter-intuitive behavior ! There are only these exceptions to this rule: String class has overridden the equality operators to provide value equality semantics (i.e. the String class returns true for '== ' for any two class instances that contain exactly the same characters in the same order).class BigInt or class PositiveValue For more detailed information read the corresponding (FxCop-checkable) MS Design Guidelines referred below. |
Literature References: |
MS Design Guidelines for Implementing Equals and the Equality Operator (==) |