编译器警告(等级 3)CS0659
更新:2007 年 11 月
错误消息
“class”重写 Object.Equals(object o) 但不重写 Object.GetHashCode()
编译器检测到 Equals 函数的重写,但没有检测到 GetHashCode 的重写。重写 Equals 意味着也要重写 GetHashCode。
有关更多信息,请参见
下面的示例生成 CS0659:
// CS0659.cs
// compile with: /W:3 /target:library
class Test
{
public override bool Equals(object o) { return true; } // CS0659
}
// OK
class Test2
{
public override bool Equals(object o) { return true; }
public override int GetHashCode() { return 0; }
}