When can a == b be false and a.Equals(b) true?

后端 未结 7 1791
离开以前
离开以前 2021-02-01 04:59

I ran into this situation today. I have an object which I\'m testing for equality; the Create() method returns a subclass implementation of MyObject.

MyObject         


        
7条回答
  •  爱一瞬间的悲伤
    2021-02-01 05:14

    I believe that a == b will check if the referenced object is the same.

    Usually to see if the value is the same a.Equals(b) is used (this often needs to be overridden in order to work).

提交回复
热议问题