Question

I know it's not very smart to use HashCode as a unique identifier,

but let's say I have two variables on the same HashCode is the only way I can get them,

how can I tell the difference?

Was it helpful?

Solution

You should be able to determine if the references are equal.

Try using the ReferenceEquals function to check if you have a reference to the same object.

OTHER TIPS

It's pretty much covered in the documentation. Assuming you have only the hash code:

The default implementation of the GetHashCode method does not guarantee unique return values for different objects. Furthermore, the .NET Framework does not guarantee the default implementation of the GetHashCode method, and the value it returns will be the same between different versions of the .NET Framework. Consequently, the default implementation of this method must not be used as a unique object identifier for hashing purposes.

From http://msdn.microsoft.com/en-us/library/system.object.gethashcode.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top