Operator overloading ==, !=, Equals

前端 未结 4 663
醉话见心
醉话见心 2020-12-02 17:58

I\'ve already gone through question

I understand that, it is necessary to implement ==, != and Equals().

publ         


        
4条回答
  •  离开以前
    2020-12-02 18:38

    I think you declared the Equals method like this:

    public override bool Equals(BOX obj)
    

    Since the object.Equals method takes an object, there is no method to override with this signature. You have to override it like this:

    public override bool Equals(object obj)
    

    If you want type-safe Equals, you can implement IEquatable.

提交回复
热议问题