Table of Contents

Class SynchronizedSet<T>

Namespace
Ecng.Collections
Assembly
Ecng.Collections.dll

Represents a thread-safe set that supports optional indexing and range-based operations.

public class SynchronizedSet<T> : SynchronizedCollection<T, ISet<T>>, INotifyList<T>, INotifyCollection<T>, IList<T>, IList, ICollection, ISynchronizedCollection<T>, ISynchronizedCollection, ISet<T>, ICollectionEx<T>, ICollection<T>, IEnumerable<T>, IEnumerable

Type Parameters

T

The element type.

Inheritance
SynchronizedSet<T>
Implements
ISet<T>
Derived
Inherited Members
Extension Methods

Constructors

SynchronizedSet()

Initializes a new instance of the SynchronizedSet<T> class.

public SynchronizedSet()

SynchronizedSet(bool)

Initializes a new instance of the SynchronizedSet<T> class with an option to enable indexing.

public SynchronizedSet(bool allowIndexing)

Parameters

allowIndexing bool

True to enable indexing; otherwise, false.

SynchronizedSet(bool, IEnumerable<T>, IEqualityComparer<T>)

Initializes a new instance of the SynchronizedSet<T> class with control over indexing, an existing collection, and comparer.

public SynchronizedSet(bool allowIndexing, IEnumerable<T> collection, IEqualityComparer<T> comparer)

Parameters

allowIndexing bool

True to enable indexing; otherwise, false.

collection IEnumerable<T>

The collection whose elements are copied to the new set.

comparer IEqualityComparer<T>

The comparer to use for comparing elements.

SynchronizedSet(bool, IEqualityComparer<T>)

Initializes a new instance of the SynchronizedSet<T> class with indexing and a custom comparer.

public SynchronizedSet(bool allowIndexing, IEqualityComparer<T> comparer)

Parameters

allowIndexing bool

True to enable indexing; otherwise, false.

comparer IEqualityComparer<T>

The comparer to use for comparing elements.

SynchronizedSet(bool, ISet<T>)

Initializes a new instance of the SynchronizedSet<T> class using the specified set as the inner collection.

protected SynchronizedSet(bool allowIndexing, ISet<T> innerCollection)

Parameters

allowIndexing bool

True to enable indexing; otherwise, false.

innerCollection ISet<T>

The inner set for the synchronized collection.

SynchronizedSet(IEnumerable<T>)

Initializes a new instance of the SynchronizedSet<T> class from an existing collection.

public SynchronizedSet(IEnumerable<T> collection)

Parameters

collection IEnumerable<T>

The collection whose elements are copied to the new set.

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

Initializes a new instance of the SynchronizedSet<T> class from an existing collection and comparer.

public SynchronizedSet(IEnumerable<T> collection, IEqualityComparer<T> comparer)

Parameters

collection IEnumerable<T>

The collection whose elements are copied to the new set.

comparer IEqualityComparer<T>

The comparer to use for comparing elements.

SynchronizedSet(IEqualityComparer<T>)

Initializes a new instance of the SynchronizedSet<T> class with a specified comparer.

public SynchronizedSet(IEqualityComparer<T> comparer)

Parameters

comparer IEqualityComparer<T>

The comparer to use for comparing elements.

Properties

ThrowIfDuplicate

Gets or sets a value indicating whether an exception is thrown when adding a duplicate element.

public bool ThrowIfDuplicate { get; set; }

Property Value

bool

Methods

AddRange(IEnumerable<T>)

Adds a range of items to the set.

public void AddRange(IEnumerable<T> items)

Parameters

items IEnumerable<T>

The items to add.

ExceptWith(IEnumerable<T>)

Removes all elements in the specified collection from the current set.

public void ExceptWith(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection of items to remove from the set.

IntersectWith(IEnumerable<T>)

Modifies the current set so that it contains only elements that are also in a specified collection.

public void IntersectWith(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to compare to the current set.

IsProperSubsetOf(IEnumerable<T>)

Determines whether the current set is a proper subset of a specified collection.

public bool IsProperSubsetOf(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to compare to the current set.

Returns

bool

True if the set is a proper subset of other; otherwise, false.

IsProperSupersetOf(IEnumerable<T>)

Determines whether the current set is a proper superset of a specified collection.

public bool IsProperSupersetOf(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to compare to the current set.

Returns

bool

True if the set is a proper superset of other; otherwise, false.

IsSubsetOf(IEnumerable<T>)

Determines whether the current set is a subset of a specified collection.

public bool IsSubsetOf(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to compare to the current set.

Returns

bool

True if the set is a subset of other; otherwise, false.

IsSupersetOf(IEnumerable<T>)

Determines whether the current set is a superset of a specified collection.

public bool IsSupersetOf(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to compare to the current set.

Returns

bool

True if the set is a superset of other; otherwise, false.

OnAdd(T)

Adds an item to the inner collection.

protected override void OnAdd(T item)

Parameters

item T

The item to add.

OnAdded(T)

Invokes the Added event and notifies of a change after adding an item.

protected override void OnAdded(T item)

Parameters

item T

The added item.

OnAdding(T)

Invokes the Adding event before adding an item.

protected override bool OnAdding(T item)

Parameters

item T

The item to add.

Returns

bool

True if the addition should proceed; otherwise, false.

OnClear()

Removes all items from the inner collection.

protected override void OnClear()

OnGetItem(int)

Retrieves an item at the specified index from the inner collection.

protected override T OnGetItem(int index)

Parameters

index int

The zero-based index of the item to retrieve.

Returns

T

The item at the specified index.

OnIndexOf(T)

When overridden in a derived class, determines the index of a specific item in the collection.

protected override int OnIndexOf(T item)

Parameters

item T

The item to locate in the collection.

Returns

int

The index of the item if found in the collection; otherwise, -1.

OnInsert(int, T)

Inserts an item into the inner collection at the specified index.

protected override void OnInsert(int index, T item)

Parameters

index int

The zero-based index at which to insert the item.

item T

The item to insert.

OnRemove(T)

Removes an item from the inner collection.

protected override bool OnRemove(T item)

Parameters

item T

The item to remove.

Returns

bool

True if the item was removed; otherwise, false.

OnRemoveAt(int)

Removes an item from the inner collection at the specified index.

protected override void OnRemoveAt(int index)

Parameters

index int

The zero-based index of the item to remove.

OnRemoved(T)

Invokes the Removed event and notifies of a change after removing an item.

protected override void OnRemoved(T item)

Parameters

item T

The removed item.

Overlaps(IEnumerable<T>)

Determines whether the current set overlaps with the specified collection.

public bool Overlaps(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to compare to the current set.

Returns

bool

True if the sets overlap; otherwise, false.

RemoveRange(IEnumerable<T>)

Removes a range of items from the set.

public void RemoveRange(IEnumerable<T> items)

Parameters

items IEnumerable<T>

The items to remove.

RemoveRange(int, int)

Removes a specified number of items starting at the given index. Not yet implemented.

public int RemoveRange(int index, int count)

Parameters

index int

The starting index.

count int

The number of items to remove.

Returns

int

The number of items removed.

Exceptions

NotImplementedException

Always thrown.

SetEquals(IEnumerable<T>)

Determines whether the current set and a specified collection contain the same elements.

public bool SetEquals(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to compare to the current set.

Returns

bool

True if the sets contain the same elements; otherwise, false.

SymmetricExceptWith(IEnumerable<T>)

Modifies the current set so that it contains only elements that are present either in the current set or in the specified collection, but not both.

public void SymmetricExceptWith(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to compare to the current set.

TryAdd(T)

Attempts to add the specified item to the set without throwing an exception for duplicates.

public bool TryAdd(T item)

Parameters

item T

The item to add.

Returns

bool

True if the item was added; otherwise, false.

UnionWith(IEnumerable<T>)

Modifies the current set so that it contains all elements that are present in both the current set and in the specified collection.

public void UnionWith(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to compare to the current set.

Events

AddedRange

Occurs when multiple items have been added to the set.

public event Action<IEnumerable<T>> AddedRange

Event Type

Action<IEnumerable<T>>

RemovedRange

Occurs when multiple items have been removed from the set.

public event Action<IEnumerable<T>> RemovedRange

Event Type

Action<IEnumerable<T>>