Mike9900 <Mi******@discussions.microsoft.comwrote:
I am wondering why GetHashCode() for the string is using two differemt
algorithms in .NET Framework 1.1 and 2.
Presumably because MS found a better algorithm - potentially the new
one is faster, has fewer collisions, or has a better distribution. I
don't know - but it's entirely reasonable for it to change.
This is creating a big problem, because we relied on this hashcode as
unique.
You shouldn't rely on a hashcode as being unique in the first place
(it's not - there can be multiple strings with the same hashcode) and
you shouldn't rely on a hashcode being the same even across two *runs*
necesasrily let alone between two versions of the framework.
How can we fix this problem?
Well, you can probably dig up the 1.1 implementation somewhere, but you
should urgently review your code to see where else you're making the
same inaccurate assumption. Hashcodes should be used as a quick "first
pass" to check for equality (where the hash codes being equal does
*not* mean that objects are necessarily equal - only that if the hash
codes are not equal, the objects should definitely not be equal) in a
way which allows you to find equal objects quickly.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too