What's wrong with defining operator == but not defining Equals() or GetHashCode()?

前端 未结 8 1276
逝去的感伤
逝去的感伤 2020-12-10 01:34

For the code below

public struct Person
{
    public int ID;
    public static bool operator ==(Person a, Person b) { return  a.Equals(b); }
    public stati         


        
8条回答
  •  庸人自扰
    2020-12-10 01:40

    Read the MSDN pages.

    CS0660

    CS0661

    The compiler is basically saying: "Since you are saying know how to compare your object, you should make it compare that way all the time."

提交回复
热议问题