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

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

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

9条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-11 19:20

    It is not necessary, nobody will kill you if you do not do that.

    However, do notice that it is often more natural to write (A == B) than A.Equals(B). If you provide both methods, it will be easier for consumers of your code.

提交回复
热议问题