Compiler Error CS0216
The operator 'operator' requires a matching operator 'missing_operator' to also be defined
A user-defined == operator requires a user-defined != operator, and vice versa.
The same applies also to a user-defined true operator and a user-defined false operator.
The following sample generates CS0216:
// CS0216.cs
class MyClass
{
public static bool operator == (MyClass MyIntLeft, MyClass MyIntRight) // CS0216
{
return MyIntLeft == MyIntRight;
}
// to resolve, uncomment the following operator definition
/*
public static bool operator != (MyClass MyIntLeft, MyClass MyIntRight)
{
return MyIntLeft != MyIntRight;
}
*/
public override bool Equals (object obj)
{
return base.Equals (obj);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public static void Main()
{
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback: