Why use GetHashCode() over Equals()?
问题 HashSet<T>.Add first compares the results of GetHashCode . If those are equal, it calls Equals . Now, my understanding is in order to implement GetHashCode , something must be done with the fields of an object. A simple example implementation can be found at What is the best algorithm for an overridden System.Object.GetHashCode?. In my test comparing both on 1.000.000 pairs of objects filled with random data, performance is more or less equal between the two. GetHashCode is implemented as in