Show / Hide Table of Contents

    Class ConcurrentHashSet<T>

    Represents a thread-safe hash-based unique collection.

    Inheritance
    System.Object
    ConcurrentHashSet<T>
    Implements
    System.Collections.Generic.IReadOnlyCollection<T>
    System.Collections.Generic.ICollection<T>
    System.Collections.Generic.IEnumerable<T>
    System.Collections.IEnumerable
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: ConcurrentCollections
    Assembly: Mapsui.dll
    Syntax
    public class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T>, IEnumerable<T>, IEnumerable
    Type Parameters
    Name Description
    T

    The type of the items in the collection.

    Remarks

    All public members of ConcurrentHashSet<T> are thread-safe and may be used concurrently from multiple threads.

    Constructors

    | Improve this Doc View Source

    ConcurrentHashSet()

    Initializes a new instance of the ConcurrentHashSet<T> class that is empty, has the default concurrency level, has the default initial capacity, and uses the default comparer for the item type.

    Declaration
    public ConcurrentHashSet()
    | Improve this Doc View Source

    ConcurrentHashSet(IEnumerable<T>)

    Initializes a new instance of the ConcurrentHashSet<T> class that contains elements copied from the specified System.Collections.IEnumerable{T}, has the default concurrency level, has the default initial capacity, and uses the default comparer for the item type.

    Declaration
    public ConcurrentHashSet(IEnumerable<T> collection)
    Parameters
    Type Name Description
    System.Collections.Generic.IEnumerable<T> collection

    The System.Collections.IEnumerable{T} whose elements are copied to the new ConcurrentHashSet<T>.

    Exceptions
    Type Condition
    System.ArgumentNullException

    collection is a null reference.

    | Improve this Doc View Source

    ConcurrentHashSet(IEnumerable<T>, IEqualityComparer<T>)

    Initializes a new instance of the ConcurrentHashSet<T> class that contains elements copied from the specified System.Collections.IEnumerable, has the default concurrency level, has the default initial capacity, and uses the specified System.Collections.Generic.IEqualityComparer{T}.

    Declaration
    public ConcurrentHashSet(IEnumerable<T> collection, IEqualityComparer<T> comparer)
    Parameters
    Type Name Description
    System.Collections.Generic.IEnumerable<T> collection

    The System.Collections.IEnumerable{T} whose elements are copied to the new ConcurrentHashSet<T>.

    System.Collections.Generic.IEqualityComparer<T> comparer

    The System.Collections.Generic.IEqualityComparer{T} implementation to use when comparing items.

    Exceptions
    Type Condition
    System.ArgumentNullException

    collection is a null reference (Nothing in Visual Basic).

    | Improve this Doc View Source

    ConcurrentHashSet(IEqualityComparer<T>)

    Initializes a new instance of the ConcurrentHashSet<T> class that is empty, has the specified concurrency level and capacity, and uses the specified System.Collections.Generic.IEqualityComparer{T}.

    Declaration
    public ConcurrentHashSet(IEqualityComparer<T> comparer)
    Parameters
    Type Name Description
    System.Collections.Generic.IEqualityComparer<T> comparer

    The System.Collections.Generic.IEqualityComparer{T} implementation to use when comparing items.

    | Improve this Doc View Source

    ConcurrentHashSet(Int32, IEnumerable<T>, IEqualityComparer<T>)

    Initializes a new instance of the ConcurrentHashSet<T> class that contains elements copied from the specified System.Collections.IEnumerable, has the specified concurrency level, has the specified initial capacity, and uses the specified System.Collections.Generic.IEqualityComparer{T}.

    Declaration
    public ConcurrentHashSet(int concurrencyLevel, IEnumerable<T> collection, IEqualityComparer<T> comparer)
    Parameters
    Type Name Description
    System.Int32 concurrencyLevel

    The estimated number of threads that will update the ConcurrentHashSet<T> concurrently.

    System.Collections.Generic.IEnumerable<T> collection

    The System.Collections.IEnumerable{T} whose elements are copied to the new ConcurrentHashSet<T>.

    System.Collections.Generic.IEqualityComparer<T> comparer

    The System.Collections.Generic.IEqualityComparer{T} implementation to use when comparing items.

    Exceptions
    Type Condition
    System.ArgumentNullException

    collection is a null reference.

    System.ArgumentOutOfRangeException

    concurrencyLevel is less than 1.

    | Improve this Doc View Source

    ConcurrentHashSet(Int32, Int32)

    Initializes a new instance of the ConcurrentHashSet<T> class that is empty, has the specified concurrency level and capacity, and uses the default comparer for the item type.

    Declaration
    public ConcurrentHashSet(int concurrencyLevel, int capacity)
    Parameters
    Type Name Description
    System.Int32 concurrencyLevel

    The estimated number of threads that will update the ConcurrentHashSet<T> concurrently.

    System.Int32 capacity

    The initial number of elements that the ConcurrentHashSet<T> can contain.

    Exceptions
    Type Condition
    System.ArgumentOutOfRangeException

    concurrencyLevel is less than 1.

    System.ArgumentOutOfRangeException

    capacity is less than 0.

    | Improve this Doc View Source

    ConcurrentHashSet(Int32, Int32, IEqualityComparer<T>)

    Initializes a new instance of the ConcurrentHashSet<T> class that is empty, has the specified concurrency level, has the specified initial capacity, and uses the specified System.Collections.Generic.IEqualityComparer{T}.

    Declaration
    public ConcurrentHashSet(int concurrencyLevel, int capacity, IEqualityComparer<T> comparer)
    Parameters
    Type Name Description
    System.Int32 concurrencyLevel

    The estimated number of threads that will update the ConcurrentHashSet<T> concurrently.

    System.Int32 capacity

    The initial number of elements that the ConcurrentHashSet<T> can contain.

    System.Collections.Generic.IEqualityComparer<T> comparer

    The System.Collections.Generic.IEqualityComparer{T} implementation to use when comparing items.

    Exceptions
    Type Condition
    System.ArgumentOutOfRangeException

    concurrencyLevel is less than 1. -or- capacity is less than 0.

    Properties

    | Improve this Doc View Source

    Count

    Gets the number of items contained in the ConcurrentHashSet<T>.

    Declaration
    public int Count { get; }
    Property Value
    Type Description
    System.Int32

    The number of items contained in the ConcurrentHashSet<T>.

    Remarks

    Count has snapshot semantics and represents the number of items in the ConcurrentHashSet<T> at the moment when Count was accessed.

    | Improve this Doc View Source

    IsEmpty

    Gets a value that indicates whether the ConcurrentHashSet<T> is empty.

    Declaration
    public bool IsEmpty { get; }
    Property Value
    Type Description
    System.Boolean

    true if the ConcurrentHashSet<T> is empty; otherwise, false.

    Methods

    | Improve this Doc View Source

    Add(T)

    Adds the specified item to the ConcurrentHashSet<T>.

    Declaration
    public bool Add(T item)
    Parameters
    Type Name Description
    T item

    The item to add.

    Returns
    Type Description
    System.Boolean

    true if the items was added to the ConcurrentHashSet<T> successfully; false if it already exists.

    Exceptions
    Type Condition
    System.OverflowException

    The ConcurrentHashSet<T> contains too many items.

    | Improve this Doc View Source

    Clear()

    Removes all items from the ConcurrentHashSet<T>.

    Declaration
    public void Clear()
    | Improve this Doc View Source

    Contains(T)

    Determines whether the ConcurrentHashSet<T> contains the specified item.

    Declaration
    public bool Contains(T item)
    Parameters
    Type Name Description
    T item

    The item to locate in the ConcurrentHashSet<T>.

    Returns
    Type Description
    System.Boolean

    true if the ConcurrentHashSet<T> contains the item; otherwise, false.

    | Improve this Doc View Source

    GetEnumerator()

    Returns an enumerator that iterates through the ConcurrentHashSet<T>.

    Declaration
    public IEnumerator<T> GetEnumerator()
    Returns
    Type Description
    System.Collections.Generic.IEnumerator<T>

    An enumerator for the ConcurrentHashSet<T>.

    Remarks

    The enumerator returned from the collection is safe to use concurrently with reads and writes to the collection, however it does not represent a moment-in-time snapshot of the collection. The contents exposed through the enumerator may contain modifications made to the collection after GetEnumerator() was called.

    | Improve this Doc View Source

    TryRemove(T)

    Attempts to remove the item from the ConcurrentHashSet<T>.

    Declaration
    public bool TryRemove(T item)
    Parameters
    Type Name Description
    T item

    The item to remove.

    Returns
    Type Description
    System.Boolean

    true if an item was removed successfully; otherwise, false.

    Explicit Interface Implementations

    | Improve this Doc View Source

    ICollection<T>.Add(T)

    Declaration
    void ICollection<T>.Add(T item)
    Parameters
    Type Name Description
    T item
    | Improve this Doc View Source

    ICollection<T>.CopyTo(T[], Int32)

    Declaration
    void ICollection<T>.CopyTo(T[] array, int arrayIndex)
    Parameters
    Type Name Description
    T[] array
    System.Int32 arrayIndex
    | Improve this Doc View Source

    ICollection<T>.IsReadOnly

    Declaration
    bool ICollection<T>.IsReadOnly { get; }
    Returns
    Type Description
    System.Boolean
    | Improve this Doc View Source

    ICollection<T>.Remove(T)

    Declaration
    bool ICollection<T>.Remove(T item)
    Parameters
    Type Name Description
    T item
    Returns
    Type Description
    System.Boolean
    | Improve this Doc View Source

    IEnumerable.GetEnumerator()

    Declaration
    IEnumerator IEnumerable.GetEnumerator()
    Returns
    Type Description
    System.Collections.IEnumerator

    Implements

    System.Collections.Generic.IReadOnlyCollection<T>
    System.Collections.Generic.ICollection<T>
    System.Collections.Generic.IEnumerable<T>
    System.Collections.IEnumerable
    • Improve this Doc
    • View Source
    Back to top Generated by DocFX