GetHashCode mostly exists for one purpose: to serve as a hash function when the object is used as a key in a hash table. ... A hash table is a data structure that associates a value with a key.
What is the purpose of GetHashCode?
The GetHashCode method provides this hash code for algorithms that need quick checks of object equality. For information about how hash codes are used in hash tables and for some additional hash code algorithms, see the Hash Function entry in Wikipedia. Two objects that are equal return hash codes that are equal.
Do I need to implement GetHashCode?
It s important to implement both equals and gethashcode, due to collisions, in particular while using dictionaries. if two object returns same hashcode, they are inserted in the dictionary with chaining. While accessing the item equals method is used.