SynchronizedCollection<T> Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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 |
| 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. |