Is Object.GetHashCode() unique to a reference or a value?

后端 未结 6 989
南方客
南方客 2020-12-24 12:58

The MSDN documentation on Object.GetHashCode() describes 3 contradicting rules for how the method should work.

  1. If two objects of the same type represent the
6条回答
  •  天涯浪人
    2020-12-24 13:26

    By default it does it based on the reference to the object, but that means that it's the exact same object, so both would return the same hash. But a hash should be based on the value, like in the case of the string class. "a" and "b" would have a different hash, but "a" and "a" would return the same hash.

提交回复
热议问题