Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Operators should have symmetrical overloads
Collapse the table of content
Expand the table of content

Operators should have symmetrical overloads

TypeName

OperatorsShouldHaveSymmetricalOverloads

CheckId

CA2226

Category

Microsoft.Usage

Breaking Change

NonBreaking

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

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.

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

Do not exclude a warning from this rule. Your type will not work in a manner that is consistent with the .NET Framework.

Community Additions

ADD
Show:
© 2015 Microsoft