buu <ah*@a.comwrote:
I'm using getHashCode sub from String object, but sometimes it gives me
duplicate values for different strings.
Yes, it will.
Difference is always when there are some numbers in strings.
Is there any better/new getHash code function or any way to do some better
hashing?
Hashing will always give duplicate values when there are more potential
"source" values than "hash" values (as there clearly are in the case of
strings hashing to any fixed size hash).
If you want to use a hash for integrity checking etc you should use the
classes derived from System.Security.Cryptography.HashAlgorithm - but
if it's just for a hash table or similar structure, then GetHashCode
should be absolutely fine.
What's your actual use case?
--
Jon Skeet - <sk***@pobox.com>
Web site:
http://www.pobox.com/~skeet
Blog:
http://www.msmvps.com/jon_skeet
C# in Depth:
http://csharpindepth.com