My search for a helper to correctly combine constituent hashcodes for GetHashCode()
seemed to garner some hostility. I got the impression from the comments that some C# developers don't think you should override GetHashCode()
often - certainly some commenters seemed to think that a library for helping get the behaviour right would be useless. Such functionality was considered useful enough in Java for the Java community to ask for it to be added to the JDK, and it's now in JDK 7.
Is there some fundamental reason that in C# you don't need to - or should definitely not - override GetHashCode()
(and correspondingly, Equals()
) as often as in Java? I find myself doing this often with Java, for example whenever I create a type that I know I want to keep in a HashSet
or use as a key in a HashMap
(equivalently, .net Dictionary
).