S
Stephan Keil
Hi all,
I am somewhat confused by the Object.GetHashCode() documentation. What I am
looking for, is a hash code, which is bound to the _identity_ of an
object, not to it's _value_ (see other thread "Object identity").
In the documentation, the statement
"The hash function must return exactly the same value regardless of any
changes that are made to the object"
suggestes that the hash code is bound to an object _identity_ (that would
be useful for me).
But this contradicts to the statement
"If two objects of the same type represent the same value, the hash
function must return the same constant value for either object"
(saying that the hash code is bound to the object's _value_) and to the
examples in the documentation, e.g.
public struct Int32 {
public int value;
//other methods...
public override int GetHashCode() { return value; }
}
Which statement is right? Or where am I wrong? (I assume that the hash code
refers to the value, not the identity. This - unfortunately - would not
solve my problems, see other thread "Object identity").
- Stephan
I am somewhat confused by the Object.GetHashCode() documentation. What I am
looking for, is a hash code, which is bound to the _identity_ of an
object, not to it's _value_ (see other thread "Object identity").
In the documentation, the statement
"The hash function must return exactly the same value regardless of any
changes that are made to the object"
suggestes that the hash code is bound to an object _identity_ (that would
be useful for me).
But this contradicts to the statement
"If two objects of the same type represent the same value, the hash
function must return the same constant value for either object"
(saying that the hash code is bound to the object's _value_) and to the
examples in the documentation, e.g.
public struct Int32 {
public int value;
//other methods...
public override int GetHashCode() { return value; }
}
Which statement is right? Or where am I wrong? (I assume that the hash code
refers to the value, not the identity. This - unfortunately - would not
solve my problems, see other thread "Object identity").
- Stephan