Hash codes are not associated with identification; they relate to equality. In fact, you can say that they are not equal:
- If two objects have the same hash code, they can be equal
- If two objects have different hash codes, they are not equal
The hash codes are not unique and do not guarantee equality (two objects can have the same hash, but still be unequal).
As for their use: they are almost always used to quickly select, possibly equal objects, then to check the actual equality, usually in a key / value map (for example, Dictionary<TKey, TValue> ) or a set (for example, HashSet<T> ) .
source share