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
T
The 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
capacity
int
Methods
AddRange(IEnumerable<T>)
Adds a range of items to the list in a thread-safe manner.
public void AddRange(IEnumerable<T> items)
Parameters
items
IEnumerable<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
index
intThe zero-based starting index of the range to retrieve.
count
intThe 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
item
TThe item that was added.
OnGetItem(int)
Retrieves an item at the specified index from the inner list.
protected override T OnGetItem(int index)
Parameters
index
intThe 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
item
TThe 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
index
intThe zero-based index at which to insert the item.
item
TThe item to insert.
OnRemoveAt(int)
Removes an item from the inner list at the specified index.
protected override void OnRemoveAt(int index)
Parameters
index
intThe 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
item
TThe 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
items
IEnumerable<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
index
intThe zero-based starting index of the range to remove.
count
intThe number of items to remove.
Returns
- int
The number of items actually removed.
Exceptions
- ArgumentOutOfRangeException
Thrown when
index
is less than -1 orcount
is 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>>