Class SynchronizedList<T>
- Namespace
- Ecng.Collections
- Assembly
- Ecng.Collections.dll
Represents a thread-safe list that supports range operations and notification events.
public class SynchronizedList<T> : SynchronizedCollection<T, List<T>>, IList, ICollection, ISynchronizedCollection<T>, ISynchronizedCollection, INotifyListEx<T>, INotifyList<T>, INotifyCollection<T>, IListEx<T>, IList<T>, ICollectionEx<T>, ICollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
TThe type of elements in the list.
- Inheritance
-
BaseCollection<T, List<T>>SynchronizedCollection<T, List<T>>SynchronizedList<T>
- Implements
-
INotifyList<T>IListEx<T>IList<T>ICollection<T>IEnumerable<T>
- Derived
- Inherited Members
- Extension Methods
Constructors
SynchronizedList()
Initializes a new instance of the SynchronizedList<T> class with default capacity.
public SynchronizedList()
SynchronizedList(int)
Represents a thread-safe list that supports range operations and notification events.
public SynchronizedList(int capacity)
Parameters
capacityint
Methods
AddRange(IEnumerable<T>)
Adds a range of items to the list in a thread-safe manner.
public void AddRange(IEnumerable<T> items)
Parameters
itemsIEnumerable<T>The items to add.
Exceptions
- ArgumentNullException
Thrown when an item is null and CheckNullableItems is true.
GetRange(int, int)
Retrieves a range of items from the list starting at the specified index, in a thread-safe manner.
public IEnumerable<T> GetRange(int index, int count)
Parameters
indexintThe zero-based starting index of the range to retrieve.
countintThe number of items to retrieve.
Returns
- IEnumerable<T>
An enumerable containing the specified range of items.
OnAdded(T)
Called after an item is added to the list, raising the AddedRange event.
protected override void OnAdded(T item)
Parameters
itemTThe item that was added.
OnGetItem(int)
Retrieves an item at the specified index from the inner list.
protected override T OnGetItem(int index)
Parameters
indexintThe zero-based index of the item to retrieve.
Returns
- T
The item at the specified index.
OnIndexOf(T)
Returns the index of the specified item in the inner list.
protected override int OnIndexOf(T item)
Parameters
itemTThe item to locate.
Returns
- int
The zero-based index of the item, or -1 if not found.
OnInsert(int, T)
Inserts an item into the inner list at the specified index.
protected override void OnInsert(int index, T item)
Parameters
indexintThe zero-based index at which to insert the item.
itemTThe item to insert.
OnRemoveAt(int)
Removes an item from the inner list at the specified index.
protected override void OnRemoveAt(int index)
Parameters
indexintThe zero-based index of the item to remove.
OnRemoved(T)
Called after an item is removed from the list, raising the RemovedRange event.
protected override void OnRemoved(T item)
Parameters
itemTThe item that was removed.
RemoveRange(IEnumerable<T>)
Removes a range of items from the list in a thread-safe manner.
public void RemoveRange(IEnumerable<T> items)
Parameters
itemsIEnumerable<T>The items to remove.
RemoveRange(int, int)
Removes a range of items from the list starting at the specified index, in a thread-safe manner.
public int RemoveRange(int index, int count)
Parameters
indexintThe zero-based starting index of the range to remove.
countintThe number of items to remove.
Returns
- int
The number of items actually removed.
Exceptions
- ArgumentOutOfRangeException
Thrown when
indexis less than -1 orcountis less than or equal to zero.
Events
AddedRange
Occurs when a range of items is added to the list.
public event Action<IEnumerable<T>> AddedRange
Event Type
- Action<IEnumerable<T>>
RemovedRange
Occurs when a range of items is removed from the list.
public event Action<IEnumerable<T>> RemovedRange
Event Type
- Action<IEnumerable<T>>