更新:2007 年 11 月

错误消息

“class”定义运算符 == 或运算符 !=,但不重写 Object.Equals(object o)

编译器检测到用户定义的相等运算符或不相等运算符,但没有检测到 Equals 函数的重写。用户定义的相等运算符或不相等运算符意味着也要重写 Equals 函数。

下面的示例生成 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()
   {
   }
}