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.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for