All rules
CA2226Usage Enabled by default: No

Operators should have symmetrical overloads

Operators should have symmetrical overloads

Microsoft docs

Description

There are no circumstances where either equality or inequality is applicable to instances of a type, and the opposite operator is undefined. Types typically implement the inequality operator by returning the negated value of the equality operator.

The C# compiler issues an error for violations of this rule.

Cause

A type implements the equality or inequality operator and does not implement the opposite operator.

By default, this rule only looks at externally visible types, but this is configurable.

How to fix violations

To fix a violation of this rule, implement both the equality and inequality operators, or remove the one that's present.

When to suppress

Do not suppress a warning from this rule. If you do, your type will not work in a manner that's consistent with .NET.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0