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

前端 未结 8 1274
逝去的感伤
逝去的感伤 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:51

    If you override Equals and GetHashCode you wouldn't even need to override the operators, and that's a cleaner approach. Edited: it should work since this is a struct.

提交回复
热议问题