Skip to content
CShift0.32

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 new
Name Description
Create A new, empty set.
static HashSet<T> Create()

A new, empty set.

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).
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.

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).

bool Remove(T value)

Removes value from the set.

Returns whether the value was in the set.

void Clear()

Removes all values.

T[] ToArray()

A new array with the values of the set (in no particular order).