How to enforce 32bit of .net String GetHashCode() [duplicate]

試著忘記壹切 提交于 2019-12-24 00:34:30

问题


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.


回答1:


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).



来源:https://stackoverflow.com/questions/6208662/how-to-enforce-32bit-of-net-string-gethashcode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!