SynchronizedSet
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
public SynchronizedSet()
synchronizedSet = SynchronizedSet()
Initializes a new instance of the SynchronizedSet class.
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.
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.
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.
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.
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.
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.
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
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
public void AddRange(IEnumerable<T> items)
synchronizedSet.AddRange(items)
Adds a range of items to the set.
- items
- The items to add.
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.
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.
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.
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.
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.
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.
protected override void OnAdd(T item)
synchronizedSet.OnAdd(item)
Adds an item to the inner collection.
- item
- The item to add.
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.
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.
protected override void OnClear()
synchronizedSet.OnClear()
Removes all items from the inner collection.
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.
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.
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.
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.
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.
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.
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.
public void RemoveRange(IEnumerable<T> items)
synchronizedSet.RemoveRange(items)
Removes a range of items from the set.
- items
- The items to remove.
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.
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.
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.
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.
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
public event Action<IEnumerable<T>> AddedRange
synchronizedSet.AddedRange += handler
Occurs when multiple items have been added to the set.
public event Action<IEnumerable<T>> RemovedRange
synchronizedSet.RemovedRange += handler
Occurs when multiple items have been removed from the set.