Edit

Share via


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()  
   {  
   }  
}