According to MSDN: http://msdn.microsoft.com/en-us/library/system.string.gethashcode%28v=vs.110%29.aspx,
String.GetHashCode() for identical strings can differ because of:
Different versions of .NET Framework.
Different platforms (such as 32-bit and 64-bit).
Or even different application domains.
How about Guid.GetHashCode()? Will it change in above 3 situations?
I have checked that for 2, Guid.GetHashCode() does return different values.
Update
How to understand 3 regarding String.GetHashCode()? Suppose I run the same application twice, there are definitely 2 different application domains. But as I tried, the hash code are the always same as long as the target platform doesn't change. For example, "hello, world".GetHashCode().
So when could 3 happen?
And here is some of my problem context:
My server application receives some GUIDs from clients. The GUID is unique for each client. I want to distribute the client to different buckets. And I need to keep the client-bucket mapping fixed. There are many clients so I cannot keep all the seen clients in memory.
My current solution is:
- Get the hash code of the client GUID (GUID or GUID string, not decided yet).
- Use the (HashCode % bucket total number) as the bucket index.
I have to make sure the hash code stay fixed for a specific client.