Will the value that comes out of long.GetHashCode() be reliably the same across different .NET Framework-versions, OS-versions, processor-architecture and so on?
The question is based on other questions that mentions different results on different servers.
// Will I be the same everywhere?
var hash = 2170881568869167279.GetHashCode();
Bonus: Does the same go for int and uint?
Per the contract of
GetHashCode, it is not even required to be the same on the same machine in two different processes:For certain types it could be – and probably is – implemented in a way that will always return the same hash code, even on different machines. But that is an implementation detail you should not rely on – it could change without notice.
Furthermore, two different objects can legally have the same hash code. In your example with
long, on average you will have each hashcodelong.MaxValue / int.MaxValuetimes when you create the hashcode for all values fromlong.MinValuetolong.Maxvalue.Conclusion:
No, it is not a reliable way to identify an instance of an object.
When dealing with numbers, you could simply use the number itself or use a real hashing algorithm.