Per the contract of GetHashCode
, it is not even required to be the same on the same machine in two different processes:
the default implementation of this method must not be used as a unique object identifier for hashing purposes.
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 hashcode long.MaxValue / int.MaxValue
times when you create the hashcode for all values from long.MinValue
to long.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.