I am exploring the HashSet
type, but I don\'t understand where it stands in collections.
Can one use it to replace a List
In the basic intended scenario HashSet
should be used when you want more specific set operations on two collections than LINQ provides. LINQ methods like Distinct
, Union
, Intersect
and Except
are enough in most situations, but sometimes you may need more fine-grained operations, and HashSet
provides:
UnionWith
IntersectWith
ExceptWith
SymmetricExceptWith
Overlaps
IsSubsetOf
IsProperSubsetOf
IsSupersetOf
IsProperSubsetOf
SetEquals
Another difference between LINQ and HashSet
"overlapping" methods is that LINQ always returns a new IEnumerable
, and HashSet
methods modify the source collection.