Generally, two objects should only report themselves as equal if they are and always will be equivalent; mutable objects, including mutable collections, should thus generally only be considered equal to each other. Immutable collections may implement GetHashCode
efficiently by caching the GetHashCode()
values of their members; construction is O(N), and whether the hash code is computed on object construction or when it's first requested, the total lifetime cost of computing it will be at most O(N).
There's no reason any class should ever have difficulty implementing a hash code. If a class uses reference equality, the default GetHashCode
is perfect. If it uses a mutable definition of equality, the GetHashCode()
contract may be complied with by simply returning a constant. Trying to put more than a few instances into a dictionary may yield poor performance, but it's possible that someone might have a use for a dictionary with e.g. a dozen items in it, and performance would be just fine with a dictionary that size.