Since the membership of HashSet<T> based on equality of objects, and not on equality of hash code. It is perfectly legal that each member of a HashSet<T> have the same hash code if the members are different from each other according to Equals . The role that hash codes play in HashSet<T> is rapid membership testing. If you have an object and its hash code is not in the HashSet<T> , then you know that the object is not in the HashSet<T> . If you have an object and its hash code is in a HashSet<T> , you need to go through the chain of objects using the same hash code test for equality using Equals to see if the object is actually in a HashSet<T> or not. Therefore, a balanced distribution of the hash code is important. But this is not the case when unique hash codes are needed.
jason
source share