Possible Duplicate:
GetHashCode() gives different results on different servers?
I used string GetHashCode() in my .net 4.0 program and store the value in the DB. The problem is that when I run the program on different setup, 64 vs 32, .net use different hashing 开发者_如何学编程algorithm for string hashing. So I won’t get the match all the time. So does anyone know how can I just compute the 32bit of string hashing even on a 64bit build.
The simple answer is to not do that. The values are specified as platform-dependent, and the exact behavior is not defined outside of satisfying the contract of GetHashCode. It's not guaranteed to stay the same across new releases of .NET, new architectures, or even patches. Use an actual hash algorithm whose behavior is defined, such as SHA-1, CRC, or something else (depending on the actual requirements).
精彩评论