Mark <Ma**@nowhere.com> wrote:
I've built a class and overroad the Equals method. I've gotten the warning
below. I'm unfamiliar with the "GetHashCode" method. An explantion of the
method and its relation to the warning would be appreciated.
warning: 'myClass' overrides Object.Equals(object o) but does not override
Object.GetHashCode()
Basically, if you override Equals but don't override GetHashCode, your
object may not work properly when put into a HashTable. See the docs on
GetHashCode for details of it.
Personally I'd suggest ignoring the requirement to make the hash code
constant after construction - if the object is mutable and changes in a
way which affects equality, it makes sense for the hash code to change
too. However, that does mean that a hash table may not be able to look
up the object using even the same reference if you change the contents
of the object after putting it into the hashtable.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too