문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top