简体   繁体   中英

Creating overload for String.GetHashCode() to return same value in x86 and x64 environments

I have a scenario in which my server side code runs in x86 environment where as the client side runs in x64. The issue is happening that we are using String.GetHashCode() to identify the objects within the HashTable since "The behavior of GetHashCode is dependent on its implementation, which might change from one version of the common language runtime to another. " -MSDN. I used the unsafe code to create x86 equivalent GetHashCode() from the following stack overflow question: Can I depend on the values of GetHashCode() to be consistent? .

I had a few questions:

  1. Is it recommended to leave unsafe code within managed code world.
  2. How to convert the unsafe code in the above mentioned question into safe code.

创建和扩展方法,为提供的字符串生成HashCode,以便即使客户端和服务器在不同环境(x86或x64)中执行也是如此。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM