All rules
CA1046Design Enabled by default: No
Do not overload operator equals on reference types
Do not overload operator equals on reference types
Microsoft docsDescription
For reference types, the default implementation of the equality operator is almost always correct. By default, two references are equal only if they point to the same object.
Cause
A public or nested public reference type overloads the equality operator.
How to fix violations
To fix a violation of this rule, remove the implementation of the equality operator.
Example
#pragma warning disable CA1046
// The code that's violating the rule is on this line.
#pragma warning restore CA1046When to suppress
It is safe to suppress a warning from this rule when the reference type behaves like a built-in value type. If it is meaningful to do addition or subtraction on instances of the type, it is probably correct to implement the equality operator and suppress the violation.
Your vote
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0