HashSet<T>
Struct · namespace System
struct HashSet<T>A set of values (T must be a valid Dictionary key: numbers, bool, char, enums, string, or a struct with GetHashCode/Equals).
var seen = HashSet<string>.Create();if (seen.Add("a")) ... // true if the value was newStatic methods
Section titled “Static methods”| Name | Description |
|---|---|
Create |
A new, empty set. |
Create
Section titled “Create”static HashSet<T> Create()A new, empty set.
Methods
Section titled “Methods”| Name | Description |
|---|---|
IsCreated |
Whether the set has storage: made by Create() or [], not the zero value (which cannot change). |
Count |
The number of values in the set. |
Contains |
Whether value is in the set. |
Add |
Adds value to the set. |
Remove |
Removes value from the set. |
Clear |
Removes all values. |
ToArray |
A new array with the values of the set (in no particular order). |
IsCreated
Section titled “IsCreated”bool IsCreated()Whether the set has storage: made by Create() or [], not the zero value (which cannot change).
Since 0.26
int Count()The number of values in the set.
Contains
Section titled “Contains”bool Contains(T value)Whether value is in the set.
bool Add(T value)Adds value to the set.
Returns true if the value was added, false if it was already in the set.
Panics when the set was not created (HashSet<T>.IsCreated).
Remove
Section titled “Remove”bool Remove(T value)Removes value from the set.
Returns whether the value was in the set.
void Clear()Removes all values.
ToArray
Section titled “ToArray”T[] ToArray()A new array with the values of the set (in no particular order).