Редактиране

Споделяне чрез


Compiler Warning (level 3) CS0660

'class' defines operator == or operator != but does not override Object.Equals(object o)

The compiler detected the user-defined equality or inequality operator, but no override for the Object.Equals method. A user-defined equality or inequality operator implies that you also want to override the Equals method. For more information, see How to define value equality for a type.

The following sample generates CS0660:

// CS0660.cs  
// compile with: /W:3 /warnaserror  
class Test   // CS0660  
{  
   public static bool operator == (object o, Test t)  
   {  
      return true;  
   }  
  
   // uncomment the Equals function to resolve  
   // public override bool Equals(object o)  
   // {  
   //    return true;  
   // }  
  
   public override int GetHashCode()  
   {  
      return 0;  
   }  
  
   public static void Main()  
   {  
   }  
}