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

I have a scenario in which my server side code runs in an x86 environment where the client side runs in x64. The problem is that we use String.GetHashCode () to identify the objects in the HashTable, because "the behavior of GetHashCode depends on its implementation, which may vary from one version of the common language runtime to another." -MSDN. I used unsafe code to create an x86 equivalent GetHashCode () from the following question: Can I depend on the values ​​of GetHashCode () so that they are consistent? . p>

I had a few questions:

  • Whether it is recommended to leave unsafe code in the world of managed code.
  • How to convert unsafe code into the above question into safe code.
+3
source share
1 answer

A created and extensible method that generates a HashCode for the provided string, so that it will be the same even if the client and server are running in different environments (x86 or x64).

+1
source

All Articles