Equality and Hash Codes for Keys
When objects are used as Hash Table keys, equality and hashing must obey a consistent contract. In Java, if two objects are equal according to equals(), they must return the same hashCode(). In C#, Equals() and GetHashCode() must similarly agree: objects considered equal must have identical hash codes.
Equal keys must produce equal hash codes.
Unequal keys may still produce the same hash code because collisions are allowed.
The fields used for equality and hashing should remain stable while the key is stored.
Breaking the equality/hash contract can cause failed lookups or duplicate logical keys.
When overriding equality, the corresponding hash implementation must also be updated.