Table of Contents

Class SynchronizedCollection<TItem, TCollection>

Namespace
Ecng.Collections
Assembly
Ecng.Collections.dll

Represents a thread-safe collection that provides synchronization for its operations.

public abstract class SynchronizedCollection<TItem, TCollection> : BaseCollection<TItem, TCollection>, INotifyList<TItem>, INotifyCollection<TItem>, IList<TItem>, IList, ICollection, ISynchronizedCollection<TItem>, ISynchronizedCollection, ICollection<TItem>, IEnumerable<TItem>, IEnumerable where TCollection : ICollection<TItem>

Type Parameters

TItem

The type of elements in the collection.

TCollection

The type of the inner collection.

Inheritance
BaseCollection<TItem, TCollection>
SynchronizedCollection<TItem, TCollection>
Implements
IList<TItem>
Derived
Inherited Members
Extension Methods

Constructors

SynchronizedCollection(TCollection)

Represents a thread-safe collection that provides synchronization for its operations.

protected SynchronizedCollection(TCollection innerCollection)

Parameters

innerCollection TCollection

Properties

Count

Gets the number of elements contained in the collection.

public override int Count { get; }

Property Value

int

this[int]

Gets or sets the element at the specified index.

public override TItem this[int index] { get; set; }

Parameters

index int

The zero-based index of the element to get or set.

Property Value

TItem

The element at the specified index.

SyncRoot

Gets the synchronization root object used to synchronize access to the collection.

public SyncObject SyncRoot { get; }

Property Value

SyncObject

Methods

Add(TItem)

Adds an item to the collection.

public override void Add(TItem item)

Parameters

item TItem

The item to add to the collection.

Clear()

Removes all items from the collection.

public override void Clear()

Contains(TItem)

Determines whether the collection contains a specific item.

public override bool Contains(TItem item)

Parameters

item TItem

The item to locate in the collection.

Returns

bool

true if the item is found in the collection; otherwise, false.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public override IEnumerator<TItem> GetEnumerator()

Returns

IEnumerator<TItem>

An enumerator that can be used to iterate through the collection.

IndexOf(TItem)

Determines the index of a specific item in the collection.

public override int IndexOf(TItem item)

Parameters

item TItem

The item to locate in the collection.

Returns

int

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

Insert(int, TItem)

Inserts an item into the collection at the specified index.

public override void Insert(int index, TItem item)

Parameters

index int

The zero-based index at which the item should be inserted.

item TItem

The item to insert into the collection.

OnIndexOf(TItem)

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

protected abstract int OnIndexOf(TItem item)

Parameters

item TItem

The item to locate in the collection.

Returns

int

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

Remove(TItem)

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

public override bool Remove(TItem item)

Parameters

item TItem

The item to remove from the collection.

Returns

bool

true if the item was successfully removed; otherwise, false.

RemoveAt(int)

Removes the item at the specified index.

public override void RemoveAt(int index)

Parameters

index int

The zero-based index of the item to remove.