HashSet Collection Type
The HashSet class is a set collection that implements the ICollection interface and the ICollection generic interface.
Starting with the .NET Framework 4, the HashSet class implements the ISet class.
The HashSet class is based on the model of mathematical sets and provides high-performance set operations similar to accessing the keys of the Dictionary or Hashtable collections. In simple terms, the HashSet class can be thought of as a Dictionary collection without values.
A HashSet collection is not sorted and cannot contain duplicate elements. If order or element duplication is more important than performance for your application, consider using the List class together with the Sort method.
HashSet provides many mathematical set operations, such as set addition (unions) and set subtraction. The following table lists the provided HashSet operations and their mathematical equivalents.
|
HashSet(Of T) operation |
Mathematical equivalent |
|---|---|
|
Union or set addition |
|
|
Intersection |
|
|
Set subtraction |
|
|
Symmetric difference |
In addition to the listed set operations, the HashSet class also provides methods for determining set equality, overlap of sets, and whether a set is a subset or superset of another set.