Difference between Equals/equals and == operator?

前端 未结 11 943
一生所求
一生所求 2020-11-22 14:14

What is the difference between a == b and a.Equals(b)?

11条回答
  •  自闭症患者
    2020-11-22 15:02

    == checks if references are pointing to the same object in the memory

    Now,

    although the code of equals method in object class is nothing but checking == for the references, it can be overridden to add your own equality checks.

    In classes like String, the overridden method checks if the string literals are correct or not. So basically it can be used to check if value is same or not.

提交回复
热议问题