HashSet
first compares the results of GetHashCode
. If those are equal, it calls Equals
.
Now, my understanding is
GetHashCode()
gets you an integral value that you can use for hashtables. That hash code is one reason why hashtables are so performant. However there can be more than one objects with the same hashcode. That's why Equals()
is called. If the objects are not equal, they can go into the same bucket, if they are equal, then it is already in the hashtable and does not need to be added.