C # - Unable to find a confirmed answer for hashset contains comparison check

I tried to figure out how C # goes about comparing objects in a HashSet for equality.

I could not find anything here: http://msdn.microsoft.com/en-us/library/bb359438.aspx

Only when I came to stackoverflow did I read that it uses Equals () and possibly getHashCode ()

I planned to implement both methods anyway, but my question is:

What would you do to find out how a HashSet actually compares objects?

+3
source share
1 answer

It compares objects for equality using Equals. It determines which bucket to place them in using GetHashCode.

, HashSet IEqualityComparer<T>, , . , EqualityComparer<T>.Default, GetHashCode() IEquatable<T>.Equals() ( object.Equals(), IEquatable<T>).

+5

All Articles