Simplify Overriding Equals(), GetHashCode() in C# for Better Maintainability

前端 未结 3 1838
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-11 03:20

I find my self overriding Equals() and GetHashCode() frequently to implement the semantic that business objects with identical property values are

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-11 04:13

    I find my self overriding Equals() and GetHashCode() frequently

    • MSDN says : don't overload Equals et al for mutable types

    Is ^ adequate given that the contributing component values are well-distributed?

    • Yes, but hey are not always well distributed. Consider int properties. Shifting with some (small) prime numbers is advised.

提交回复
热议问题