Dictionary (HashSet and KeyedCollections) uses HashBuckets (for speed).
HashBuckets uses GetHashCode, which is Int32.
If the objects are not equal, then they must have different GetHashCode.
But two objects that are not equal can have the same GetHashCode.
If the GetHashCode code is the same, then the tie-breaker is equal to Equals.
GetHashCode comparison is faster - you want to avoid decoupling.
You need a good (unique) GetHashCode.
If the objects come from the database, and the table has a key and the key has Int32 (or less), then use this for the perfect hash code.
If your objects do not have a natural key, then you can use the GetHashCode system.
But if you have a natural key, use it.
Object Object Object Class
If your class does not override GetHashCode, it will be created from Object.
Consult against Tuple or KeyValuePair for Key as they do not create a good GetHashCode. Lots of collisions.
source share