You should not rely on the implementation of string
's GetHashCode()
other than the fact that strings of equal value will produce the same hash code - but what the particular value of the hash code will be is only required to be consistent as per the documentation for the current execution of an application - a different hash code can be returned if the application is run again.
Also the implementation of GetHashCode
might be different if you have different .NET CLR versions on the machines in question:
The behavior of GetHashCode is dependent on its implementation, which
might change from one version of the common language runtime to
another. A reason why this might happen is to improve the performance
of GetHashCode.
Instead you could just define a consistent mapping from your string key to a numeric value which would allow you to bin your nodes consistently across restarts and machine boundaries, this i.e. could be achieved by converting the string into a byte array (i.e using Encoding.UTF8.GetBytes()
) and then converting the byte array to a number (either using a lossy conversion using just 64 bits or i.e using BigInteger
)