SynchronizedSet

Ecng.Collections

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

Hereda de: SynchronizedCollection<T, ISet<T>>

Implementa: ISet<T>, ICollection<T>, IEnumerable<T>, IEnumerable, ICollectionEx<T>

Constructores

SynchronizedSet
public SynchronizedSet()
synchronizedSet = SynchronizedSet()

Initializes a new instance of the SynchronizedSet class.

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

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

allowIndexing
True to enable indexing; otherwise, false.
innerCollection
The inner set for the synchronized collection.
SynchronizedSet
public SynchronizedSet(bool allowIndexing, IEnumerable<T> collection, IEqualityComparer<T> comparer)
synchronizedSet = SynchronizedSet(allowIndexing, collection, comparer)

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

allowIndexing
True to enable indexing; otherwise, false.
collection
The collection whose elements are copied to the new set.
comparer
The comparer to use for comparing elements.
SynchronizedSet
public SynchronizedSet(IEnumerable<T> collection, IEqualityComparer<T> comparer)
synchronizedSet = SynchronizedSet(collection, comparer)

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

collection
The collection whose elements are copied to the new set.
comparer
The comparer to use for comparing elements.
SynchronizedSet
public SynchronizedSet(IEnumerable<T> collection)
synchronizedSet = SynchronizedSet(collection)

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

collection
The collection whose elements are copied to the new set.
SynchronizedSet
public SynchronizedSet(bool allowIndexing, IEqualityComparer<T> comparer)
synchronizedSet = SynchronizedSet(allowIndexing, comparer)

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

allowIndexing
True to enable indexing; otherwise, false.
comparer
The comparer to use for comparing elements.
SynchronizedSet
public SynchronizedSet(IEqualityComparer<T> comparer)
synchronizedSet = SynchronizedSet(comparer)

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

comparer
The comparer to use for comparing elements.
SynchronizedSet
public SynchronizedSet(bool allowIndexing)
synchronizedSet = SynchronizedSet(allowIndexing)

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

allowIndexing
True to enable indexing; otherwise, false.

Propiedades

ThrowIfDuplicate
public bool ThrowIfDuplicate { get; set; }
value = synchronizedSet.ThrowIfDuplicate
synchronizedSet.ThrowIfDuplicate = value

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

Métodos

AddRange
public void AddRange(IEnumerable<T> items)
synchronizedSet.AddRange(items)

Adds a range of items to the set.

items
The items to add.
ExceptWith
public void ExceptWith(IEnumerable<T> other)
synchronizedSet.ExceptWith(other)

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

other
The collection of items to remove from the set.
IntersectWith
public void IntersectWith(IEnumerable<T> other)
synchronizedSet.IntersectWith(other)

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

other
The collection to compare to the current set.
IsProperSubsetOf
public bool IsProperSubsetOf(IEnumerable<T> other)
result = synchronizedSet.IsProperSubsetOf(other)

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

other
The collection to compare to the current set.

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

IsProperSupersetOf
public bool IsProperSupersetOf(IEnumerable<T> other)
result = synchronizedSet.IsProperSupersetOf(other)

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

other
The collection to compare to the current set.

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

IsSubsetOf
public bool IsSubsetOf(IEnumerable<T> other)
result = synchronizedSet.IsSubsetOf(other)

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

other
The collection to compare to the current set.

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

IsSupersetOf
public bool IsSupersetOf(IEnumerable<T> other)
result = synchronizedSet.IsSupersetOf(other)

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

other
The collection to compare to the current set.

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

OnAdd
protected override void OnAdd(T item)
synchronizedSet.OnAdd(item)

Adds an item to the inner collection.

item
The item to add.
OnAdded
protected override void OnAdded(T item)
synchronizedSet.OnAdded(item)

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

item
The added item.
OnAdding
protected override bool OnAdding(T item)
result = synchronizedSet.OnAdding(item)

Invokes the Adding event before adding an item.

item
The item to add.

Devuelve: True if the addition should proceed; otherwise, false.

OnClear
protected override void OnClear()
synchronizedSet.OnClear()

Removes all items from the inner collection.

OnGetItem
protected override T OnGetItem(int index)
result = synchronizedSet.OnGetItem(index)

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

index
The zero-based index of the item to retrieve.

Devuelve: The item at the specified index.

OnIndexOf
protected override int OnIndexOf(T item)
result = synchronizedSet.OnIndexOf(item)

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

item
The item to locate in the collection.

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

OnInsert
protected override void OnInsert(int index, T item)
synchronizedSet.OnInsert(index, item)

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

index
The zero-based index at which to insert the item.
item
The item to insert.
OnRemove
protected override bool OnRemove(T item)
result = synchronizedSet.OnRemove(item)

Removes an item from the inner collection.

item
The item to remove.

Devuelve: True if the item was removed; otherwise, false.

OnRemoveAt
protected override void OnRemoveAt(int index)
synchronizedSet.OnRemoveAt(index)

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

index
The zero-based index of the item to remove.
OnRemoved
protected override void OnRemoved(T item)
synchronizedSet.OnRemoved(item)

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

item
The removed item.
Overlaps
public bool Overlaps(IEnumerable<T> other)
result = synchronizedSet.Overlaps(other)

Determines whether the current set overlaps with the specified collection.

other
The collection to compare to the current set.

Devuelve: True if the sets overlap; otherwise, false.

RemoveRange
public void RemoveRange(IEnumerable<T> items)
synchronizedSet.RemoveRange(items)

Removes a range of items from the set.

items
The items to remove.
RemoveRange
public int RemoveRange(int index, int count)
result = synchronizedSet.RemoveRange(index, count)

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

index
The starting index.
count
The number of items to remove.

Devuelve: The number of items removed.

SetEquals
public bool SetEquals(IEnumerable<T> other)
result = synchronizedSet.SetEquals(other)

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

other
The collection to compare to the current set.

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

SymmetricExceptWith
public void SymmetricExceptWith(IEnumerable<T> other)
synchronizedSet.SymmetricExceptWith(other)

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.

other
The collection to compare to the current set.
System#Collections#Generic#ISet{T}#Add(T)

Adds an item to the current set and returns a value to indicate if the item was successfully added.

item
The element to add to the set.

Devuelve: True if the item is added to the set; otherwise, false.

TryAdd
public bool TryAdd(T item)
result = synchronizedSet.TryAdd(item)

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

item
The item to add.

Devuelve: True if the item was added; otherwise, false.

UnionWith
public void UnionWith(IEnumerable<T> other)
synchronizedSet.UnionWith(other)

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

other
The collection to compare to the current set.

Eventos

AddedRange
public event Action<IEnumerable<T>> AddedRange
synchronizedSet.AddedRange += handler

Occurs when multiple items have been added to the set.

RemovedRange
public event Action<IEnumerable<T>> RemovedRange
synchronizedSet.RemovedRange += handler

Occurs when multiple items have been removed from the set.