Domanda

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?

È stato utile?

Soluzione

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.

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top