What's the best strategy for Equals and GetHashCode?

后端 未结 7 1981
你的背包
你的背包 2020-11-28 11:25

I\'m working with a domain model and was thinking about the various ways that we have to implement these two methods in .NET. What is your preferred strategy?

This i

7条回答
  •  悲&欢浪女
    2020-11-28 12:14

    In addition to the answers (I am not allowed to write comments) I would like to point out that Visual Studio can autogenerate Equals and GetHashCode. See this answer: Is there a way to automatically generate equals and hashcode method in Visual Studio I was really looking for that custom implementation and didnt find it here.

    I woulld also like to link this question: Best way to compare two complex objects It is about having a nested class structure. Down in the comments one can find the case for nested class structures with Enumerations (for example with List ).

提交回复
热议问题