Edit

SynchronizedCollection<T> Class

Definition

Provides a thread-safe collection that contains objects of a type specified by the generic parameter as elements.

generic <typename T>
public ref class SynchronizedCollection : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::IList<T>, System::Collections::IList
public class SynchronizedCollection<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IList<T>, System.Collections.IList
type SynchronizedCollection<'T> = class
    interface IList<'T>
    interface ICollection<'T>
    interface seq<'T>
    interface IEnumerable
    interface IList
    interface ICollection
Public Class SynchronizedCollection(Of T)
Implements ICollection(Of T), IEnumerable(Of T), IList, IList(Of T)

Type Parameters

T

The type of object contained as items in the thread-safe collection.

Inheritance
SynchronizedCollection<T>
Derived
Attributes
Implements

Remarks

The SynchronizedCollection<T> stores data in a List<T> container and provides an object that can be set and used to synchronize access to the collection so that it is thread-safe. The IList<T> container can be recovered using the Items property. The synchronized object can be recovered using the SyncRoot property. It can only be set using one of the constructors that take the syncRoot parameter.

Constructors

Name Description
SynchronizedCollection<T>()

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

SynchronizedCollection<T>(Object, IEnumerable<T>)

Initializes a new instance of the SynchronizedCollection<T> class from a specified enumerable list of elements and with the object used to synchronize access to the thread-safe collection.

SynchronizedCollection<T>(Object, T[])

Initializes a new instance of the SynchronizedCollection<T> class from a specified array of elements and with the object used to synchronize access to the thread-safe collection.

SynchronizedCollection<T>(Object)

Initializes a new instance of the SynchronizedCollection<T> class with the object used to synchronize access to the thread-safe collection.

Properties

Name Description
Count

Gets the number of elements contained in the thread-safe collection.

Item[Int32]

Gets an element from the thread-safe collection with a specified index.

Items

Gets the list of elements contained in the thread-safe collection.

SyncRoot

Gets the object used to synchronize access to the thread-safe collection.

Methods

Name Description
Add(T)

Adds an item to the thread-safe, read-only collection.

Clear()

Removes all items from the collection.

ClearItems()

Removes all items from the collection.

Contains(T)

Determines whether the collection contains an element with a specific value.

CopyTo(T[], Int32)

Copies the elements of the collection to a specified array, starting at a particular index.

GetEnumerator()

Returns an enumerator that iterates through the synchronized collection.

IndexOf(T)

Returns the index of the first occurrence of a value in the collection.

Insert(Int32, T)

Inserts an item into the collection at a specified index.

InsertItem(Int32, T)

Inserts an item into the collection at a specified index.

Remove(T)

Removes the first occurrence of a specified item from the collection.

RemoveAt(Int32)

Removes an item at a specified index from the collection.

RemoveItem(Int32)

Removes an item at a specified index from the collection.

SetItem(Int32, T)

Replaces the item at a specified index with another item.

Explicit Interface Implementations

Name Description
ICollection.CopyTo(Array, Int32)

Copies the elements of the collection to a specified array, starting at a particular index.

ICollection.IsSynchronized

Gets a value that indicates whether the collection is thread safe.

ICollection.SyncRoot

Gets the object used to synchronize access to the thread-safe collection.

ICollection<T>.IsReadOnly

Gets a value that indicates whether the collection is read only.

IEnumerable.GetEnumerator()

Returns an enumerator that iterates through the synchronized collection.

IList.Add(Object)

Adds an element to the collection.

IList.Contains(Object)

Determines whether the collection contains an element with a specific value.

IList.IndexOf(Object)

Determines the zero-based index of an element in the collection.

IList.Insert(Int32, Object)

Inserts an object into the collection at a specified index.

IList.IsFixedSize

Gets a value that indicates whether the collection is fixed in size.

IList.IsReadOnly

Gets a value that indicates whether the collection is read only.

IList.Item[Int32]

Gets or sets the item at a specified zero-based index.

IList.Remove(Object)

Removes the first occurrence of a specified object as an element from the collection.

Extension Methods

Name Description
ToAsyncEnumerable<TSource>(IEnumerable<TSource>)

Creates a new IAsyncEnumerable<T> that iterates through source.

ToFrozenDictionary<TSource,TKey,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>)

Creates a FrozenDictionary<TKey,TValue> from an IEnumerable<T> according to specified key selector and element selector functions.

ToFrozenDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

Creates a FrozenDictionary<TKey,TValue> from an IEnumerable<T> according to specified key selector function.

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

Creates a FrozenSet<T> with the specified values.

ToImmutableArray<TSource>(IEnumerable<TSource>)

Creates an immutable array from the specified collection.

ToImmutableDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IEqualityComparer<TKey>, IEqualityComparer<TValue>)

Enumerates and transforms a sequence, and produces an immutable dictionary of its contents by using the specified key and value comparers.

ToImmutableDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IEqualityComparer<TKey>)

Enumerates and transforms a sequence, and produces an immutable dictionary of its contents by using the specified key comparer.

ToImmutableDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>)

Enumerates and transforms a sequence, and produces an immutable dictionary of its contents.

ToImmutableDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

Constructs an immutable dictionary based on some transformation of a sequence.

ToImmutableDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

Constructs an immutable dictionary from an existing collection of elements, applying a transformation function to the source keys.

ToImmutableHashSet<TSource>(IEnumerable<TSource>, IEqualityComparer<TSource>)

Enumerates a sequence, produces an immutable hash set of its contents, and uses the specified equality comparer for the set type.

ToImmutableHashSet<TSource>(IEnumerable<TSource>)

Enumerates a sequence and produces an immutable hash set of its contents.

ToImmutableList<TSource>(IEnumerable<TSource>)

Enumerates a sequence and produces an immutable list of its contents.

ToImmutableSortedDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IComparer<TKey>, IEqualityComparer<TValue>)

Enumerates and transforms a sequence, and produces an immutable sorted dictionary of its contents by using the specified key and value comparers.

ToImmutableSortedDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IComparer<TKey>)

Enumerates and transforms a sequence, and produces an immutable sorted dictionary of its contents by using the specified key comparer.

ToImmutableSortedDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>)

Enumerates and transforms a sequence, and produces an immutable sorted dictionary of its contents.

ToImmutableSortedSet<TSource>(IEnumerable<TSource>, IComparer<TSource>)

Enumerates a sequence, produces an immutable sorted set of its contents, and uses the specified comparer.

ToImmutableSortedSet<TSource>(IEnumerable<TSource>)

Enumerates a sequence and produces an immutable sorted set of its contents.

Applies to