C# C# Collections Sets and Dictionaries HashSet

How exactly does the HashSet class prevent duplicate items in its collection?

?

1 Answer

Steven Parker
Steven Parker
186,321 Points

The HashSet relies on an equality comparison method, either one associated with the type by default or one explicitly provided during instantiation, to insure that each added element is unique.

For more details, see the documentation page on HashSet.