編譯器警告 (層級 3) CS0660
更新: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()
{
}
}