System.Collections.Generic.HashSet<T> Class
Represents a set of values. Provides high-performance set operations.
Constructors
Initializes a new empty HashSet that uses the default equality comparer for the type of the elements.
public HashSet();
Initializes a new empty HashSet that uses the specified equality comparer.
public HashSet(IEqualityComparer<T> comparer);
Initializes a new HashSet that contains elements copied from the specified collection and uses the default equality comparer.
public HashSet(IEnumerable<T> collection);
Properties
Gets the number of elements contained in the HashSet.
public int Count { get; }
Gets a value indicating whether the HashSet is read-only.
public bool IsReadOnly { get; }
Methods
Adds the specified element to the set.
public bool Add(T item);
Returns true
if the element is added; false
if the element already exists.
Determines whether the set contains the specified element.
public bool Contains(T item);
Removes the specified element from the set.
public bool Remove(T item);
Modifies the current set to contain all elements that are present in itself, the specified collection, or both.
public void UnionWith(IEnumerable<T> other);
Modifies the current set to contain only elements that are also in a specified collection.
public void IntersectWith(IEnumerable<T> other);
Removes all elements in the specified collection from the current set.
public void ExceptWith(IEnumerable<T> other);
Modifies the current set to contain only elements that are present either in the set or in the specified collection, but not both.
public void SymmetricExceptWith(IEnumerable<T> other);
Copies the elements of the set to an array, starting at the specified array index.
public void CopyTo(T[] array, int arrayIndex);
Returns an enumerator that iterates through the HashSet.
public IEnumerator<T> GetEnumerator();
Explicit Interface Implementations
void ICollection<T>.Add(T item);