Is it necessary to override == and != operators when overriding the Equals method? (.NET)

后端 未结 9 1183
一向
一向 2021-01-11 19:06

Or it\'s advisable to do that? Why?

9条回答
  •  隐瞒了意图╮
    2021-01-11 19:29

    It is not necessary, but a smart thing to do.

    If you are creating a framework and another developer other than you are going to use the object you should override the == and !=. That way when a developer may use it they at least have the right logic to compare the 2 objects rather than just are the same in memory.

    I would ensure that your == & != do call your equals method.

提交回复
热议问题