Overloading operator== versus Equals()

前端 未结 6 836
生来不讨喜
生来不讨喜 2020-11-29 20:46

I\'m working on a C# project on which, until now, I\'ve used immutable objects and factories to ensure that objects of type Foo can always be compared for equal

6条回答
  •  一生所求
    2020-11-29 21:06

    It definitely smells. When overloading == you should make sure that both Equals() and GetHashCode() are also consistent. See the MSDN guidelines.

    And the only reason that this seems OK at all is that you describe your type as immutable.

提交回复
热议问题