The rule basically says:
if two object are deemed Equal then GetHashCode must return the same value (the converse is not true). So, if you override Equals the compiler forces you to take account of the this by overriding GetHashCode. Also, the value returned by GetHashCode must be immutable after construction. If it were not the bucket that an object was in in a HashTable may become invalid as the object's state changed.
Regards
Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<#Z**************@TK2MSFTNGP09.phx.gbl>
Hi,
why is it requested that when Equals() is implemented in a class that GethashCode() must be implemented as well ?
thnx
Chris
************************************************** ********************
Sent via Fuzzy Software @
http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (
http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10/09/2004
[microsoft.public.dotnet.languages.csharp]