Re: Generic Collection with reference types
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Tue, 24 Apr 2007 18:45:32 +0100
<"Ethan Strauss" <ethan dot strauss at Promega dot com>> wrote:
Overriding GetHashCode was what I was missing. That did the trick.
Do any of you have the time/desire to explain what GetHashCode is used
for? Is there anything out there that really explains the guts of
collections and how all the bits and pieces work?
The basic idea is that code is a quick way of narrowing down *possible*
matches, e.g. for keys in a hashtable.
Two keys which are equal should *definitely* have the same hashcode,
but two keys which aren't equal *might* have the same hashcode. In an
ideal world, hashcodes should be distributed such that two unequal keys
will almost always have different hashcodes.
When you look up a key in a hashtable, it first finds all the elements
with the right hashcode. After that it asks each of those whether or
not it's equal to the key you've passed in.
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- References:
- Generic Collection with reference types
- From: Ethan Strauss
- Re: Generic Collection with reference types
- From: Nicholas Paldino [.NET/C# MVP]
- Re: Generic Collection with reference types
- From: Ethan Strauss
- Generic Collection with reference types
- Prev by Date: Re: How to change MS Word data to byte[ ]
- Next by Date: Re: I keep missing Hungarian naming; still smart to abandon?
- Previous by thread: Re: Generic Collection with reference types
- Next by thread: Re: Generic Collection with reference types
- Index(es):
Relevant Pages
|