# SynchronizedList\<T>

Namespace: **Wisej.Core**

Assembly: **Wisej.Framework** (4.0.0.0)

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

{% tabs %}
{% tab title="C#" %}

```csharp
public class SynchronizedList<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, ICollection
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class SynchronizedList(Of T)
    Inherits IList(Of T)
    Implements ICollection(Of T), IEnumerable(Of T), IEnumerable, IList, ICollection
```

{% endtab %}
{% endtabs %}

## Parameters

| Name  | Description                                                          |
| ----- | -------------------------------------------------------------------- |
| **T** | The type of object contained as items in the thread-safe collection. |

## Constructors

### ![](/files/hsR4ok3152WyAf8J2C1u) SynchronizedList(capacity, collection, syncLock)

Initializes a new instance of the [SynchronizedList](https://github.com/iceteagroup/wisej-docs-api/blob/v4.0/api?q=wisej.core.synchronizedlist%601) class that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied and uses the specified *syncLock* object to synchronize its internal operations.

| Name           | Type                                                                                              | Description                                                        |
| -------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| **capacity**   | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)                                       | The optional number of element that the list can initially store.  |
| **collection** | [IEnumerable\<T>](https://docs.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1) | The optional collection whose elements are copied to the new list. |
| **syncLock**   | [Object](https://docs.microsoft.com/dotnet/api/system.object)                                     | The optional lock reference.                                       |

## Properties

### ![](/files/hsR4ok3152WyAf8J2C1u) Count

[Int32](https://docs.microsoft.com/dotnet/api/system.int32): Gets the number of elements contained in the thread-safe collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) Item(index)

[T](/api/wisej.core/general/wisej.core.synchronizedlist-less-than-t-greater-than.md): Gets an element from the thread-safe collection with a specified index.

**Throws:**

* [ArgumentOutOfRangeException](https://docs.microsoft.com/dotnet/api/system.argumentoutofrangeexception) The *index* specified is less than zero or greater than the number of items in the collection.

### ![](/files/lzopMboA31bVq8UIcbT3) Items

[IList\<T>](https://docs.microsoft.com/dotnet/api/system.collections.generic.ilist-1): Gets the list of elements contained in the thread-safe collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) SyncRoot

[Object](https://docs.microsoft.com/dotnet/api/system.object): Gets the object used to synchronize access to the thread-safe collection.

## Methods

### ![](/files/hsR4ok3152WyAf8J2C1u) Add(item)

Adds an item to the thread-safe collection.

| Parameter | Type                                                                                 | Description                                |
| --------- | ------------------------------------------------------------------------------------ | ------------------------------------------ |
| **item**  | [T](/api/wisej.core/general/wisej.core.synchronizedlist-less-than-t-greater-than.md) | The element to be added to the collection. |

### ![](/files/hsR4ok3152WyAf8J2C1u) AddRange(collection)

Adds the elements of the specified collection to the end of the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

| Parameter      | Type                                                                                              | Description                                                                                                                                                                                                                                            |
| -------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **collection** | [IEnumerable\<T>](https://docs.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1) | The collection whose elements should be added to the end of the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1). The collection itself cannot be null, but it can contain elements that are null, for reference types. |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *collection* is null.

### ![](/files/hsR4ok3152WyAf8J2C1u) BinarySearch(item)

Searches the entire sorted [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1) for an element using the default comparer and returns the zero-based index of the element.

| Parameter | Type                                                                                 | Description                                                      |
| --------- | ------------------------------------------------------------------------------------ | ---------------------------------------------------------------- |
| **item**  | [T](/api/wisej.core/general/wisej.core.synchronizedlist-less-than-t-greater-than.md) | The object to locate. The value can be null for reference types. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The zero-based index of *item* in the sorted [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1), if *item* is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than *item* or, if there is no larger element, the bitwise complement of [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) The default comparer [Comparer](https://docs.microsoft.com/dotnet/api/system.collections.generic.comparer-1) cannot find an implementation of the [IComparable](https://docs.microsoft.com/dotnet/api/system.icomparable) generic interface or the [IComparable](https://docs.microsoft.com/dotnet/api/system.icomparable) interface for the type of the collection elements.

### ![](/files/hsR4ok3152WyAf8J2C1u) BinarySearch(item, comparer)

Searches the entire sorted [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1) for an element using the specified comparer and returns the zero-based index of the element.

| Parameter    | Type                                                                                          | Description                                                                                                                                                                                                                                                               |
| ------------ | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **item**     | [T](/api/wisej.core/general/wisej.core.synchronizedlist-less-than-t-greater-than.md)          | The object to locate. The value can be null for reference types.                                                                                                                                                                                                          |
| **comparer** | [IComparer\<T>](https://docs.microsoft.com/dotnet/api/system.collections.generic.icomparer-1) | The [IComparer](https://docs.microsoft.com/dotnet/api/system.collections.generic.icomparer-1) implementation to use when comparing elements; or null to use the default comparer [Comparer](https://docs.microsoft.com/dotnet/api/system.collections.generic.comparer-1). |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The zero-based index of *item* in the sorted [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1), if *item* is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than *item* or, if there is no larger element, the bitwise complement of [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) *comparer* is null, and the default comparer [Comparer](https://docs.microsoft.com/dotnet/api/system.collections.generic.comparer-1) cannot find an implementation of the [IComparable](https://docs.microsoft.com/dotnet/api/system.icomparable) generic interface or the [IComparable](https://docs.microsoft.com/dotnet/api/system.icomparable) interface for the type of the collection elements.

### ![](/files/hsR4ok3152WyAf8J2C1u) Clear()

Removes all items from the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) Contains(item)

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

| Parameter | Type                                                                                 | Description                             |
| --------- | ------------------------------------------------------------------------------------ | --------------------------------------- |
| **item**  | [T](/api/wisej.core/general/wisej.core.synchronizedlist-less-than-t-greater-than.md) | The object to locate in the collection. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true if the element value is found in the collection; otherwise false.

### ![](/files/hsR4ok3152WyAf8J2C1u) CopyTo(array, index)

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

| Parameter | Type                                                                                     | Description                                                                                                              |
| --------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| **array** | [T\[\]](/api/wisej.core/general/wisej.core.synchronizedlist-less-than-t-greater-than.md) | The destination [Array](https://docs.microsoft.com/dotnet/api/system.array) for the elements copied from the collection. |
| **index** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)                              | The zero-based index in the array at which copying begins.                                                               |

### ![](/files/hsR4ok3152WyAf8J2C1u) Find(match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

| Parameter | Type                                                                      | Description                                                                                                                                  |
| --------- | ------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **match** | [Predicate\<T>](https://docs.microsoft.com/dotnet/api/system.predicate-1) | The [Predicate](https://docs.microsoft.com/dotnet/api/system.predicate-1) delegate that defines the conditions of the element to search for. |

**Returns:** [T](/api/wisej.core/general/wisej.core.synchronizedlist-less-than-t-greater-than.md). The first element that matches the conditions defined by the specified predicate, if found; otherwise, the default value.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *match* is null.

### ![](/files/hsR4ok3152WyAf8J2C1u) Find(startIndex, match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

| Parameter      | Type                                                                      | Description                                                                                                                                  |
| -------------- | ------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **startIndex** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)               | The zero-based starting index of the search.                                                                                                 |
| **match**      | [Predicate\<T>](https://docs.microsoft.com/dotnet/api/system.predicate-1) | The [Predicate](https://docs.microsoft.com/dotnet/api/system.predicate-1) delegate that defines the conditions of the element to search for. |

**Returns:** [T](/api/wisej.core/general/wisej.core.synchronizedlist-less-than-t-greater-than.md). The first element that matches the conditions defined by the specified predicate, if found; otherwise, the default value.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *match* is null.
* [ArgumentOutOfRangeException](https://docs.microsoft.com/dotnet/api/system.argumentoutofrangeexception) *startIndex* is outside the range of valid indexes for the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

### ![](/files/hsR4ok3152WyAf8J2C1u) FindAll(match)

Retrieves all the elements that match the conditions defined by the specified predicate.

| Parameter | Type                                                                      | Description                                                                                                                                   |
| --------- | ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| **match** | [Predicate\<T>](https://docs.microsoft.com/dotnet/api/system.predicate-1) | The [Predicate](https://docs.microsoft.com/dotnet/api/system.predicate-1) delegate that defines the conditions of the elements to search for. |

**Returns:** [List\<T>](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1). A [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1) containing all the elements that match the conditions defined by the specified predicate, if found; otherwise, an empty [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *match* is null.

### ![](/files/hsR4ok3152WyAf8J2C1u) FindIndex(match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the entire [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

| Parameter | Type                                                                      | Description                                                                                                                                  |
| --------- | ------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **match** | [Predicate\<T>](https://docs.microsoft.com/dotnet/api/system.predicate-1) | The [Predicate](https://docs.microsoft.com/dotnet/api/system.predicate-1) delegate that defines the conditions of the element to search for. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The zero-based index of the first occurrence of an element that matches the conditions defined by *match* , if found; otherwise, –1.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *match* is null.

### ![](/files/hsR4ok3152WyAf8J2C1u) FindIndex(startIndex, match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1) that extends from the specified index to the last element.

| Parameter      | Type                                                                      | Description                                                                                                                                  |
| -------------- | ------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **startIndex** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)               | The zero-based starting index of the search.                                                                                                 |
| **match**      | [Predicate\<T>](https://docs.microsoft.com/dotnet/api/system.predicate-1) | The [Predicate](https://docs.microsoft.com/dotnet/api/system.predicate-1) delegate that defines the conditions of the element to search for. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The zero-based index of the first occurrence of an element that matches the conditions defined by *match* , if found; otherwise, –1.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *match* is null.
* [ArgumentOutOfRangeException](https://docs.microsoft.com/dotnet/api/system.argumentoutofrangeexception) *startIndex* is outside the range of valid indexes for the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

### ![](/files/hsR4ok3152WyAf8J2C1u) FindIndex(startIndex, count, match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1) that starts at the specified index and contains the specified number of elements.

| Parameter      | Type                                                                      | Description                                                                                                                                  |
| -------------- | ------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **startIndex** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)               | The zero-based starting index of the search.                                                                                                 |
| **count**      | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)               | The number of elements in the section to search.                                                                                             |
| **match**      | [Predicate\<T>](https://docs.microsoft.com/dotnet/api/system.predicate-1) | The [Predicate](https://docs.microsoft.com/dotnet/api/system.predicate-1) delegate that defines the conditions of the element to search for. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The zero-based index of the first occurrence of an element that matches the conditions defined by *match* , if found; otherwise, –1.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *match* is null.
* [ArgumentOutOfRangeException](https://docs.microsoft.com/dotnet/api/system.argumentoutofrangeexception) *startIndex* is outside the range of valid indexes for the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1); or *count* is less than 0; or *startIndex* and *count* do not specify a valid section in the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

### ![](/files/hsR4ok3152WyAf8J2C1u) FindLast(match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the last occurrence within the entire [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

| Parameter | Type                                                                      | Description                                                                                                                                  |
| --------- | ------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **match** | [Predicate\<T>](https://docs.microsoft.com/dotnet/api/system.predicate-1) | The [Predicate](https://docs.microsoft.com/dotnet/api/system.predicate-1) delegate that defines the conditions of the element to search for. |

**Returns:** [T](/api/wisej.core/general/wisej.core.synchronizedlist-less-than-t-greater-than.md). The last element that matches the conditions defined by the specified predicate, if found; otherwise, the default value.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *match* is null.

### ![](/files/hsR4ok3152WyAf8J2C1u) FindLast(startIndex, match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the last occurrence within the entire [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

| Parameter      | Type                                                                      | Description                                                                                                                                  |
| -------------- | ------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **startIndex** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)               | The zero-based starting index of the search.                                                                                                 |
| **match**      | [Predicate\<T>](https://docs.microsoft.com/dotnet/api/system.predicate-1) | The [Predicate](https://docs.microsoft.com/dotnet/api/system.predicate-1) delegate that defines the conditions of the element to search for. |

**Returns:** [T](/api/wisej.core/general/wisej.core.synchronizedlist-less-than-t-greater-than.md). The last element that matches the conditions defined by the specified predicate, if found; otherwise, the default value.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *match* is null.
* [ArgumentOutOfRangeException](https://docs.microsoft.com/dotnet/api/system.argumentoutofrangeexception) *startIndex* is outside the range of valid indexes for the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

### ![](/files/hsR4ok3152WyAf8J2C1u) FindLastIndex(match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the entire [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

| Parameter | Type                                                                      | Description                                                                                                                                  |
| --------- | ------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **match** | [Predicate\<T>](https://docs.microsoft.com/dotnet/api/system.predicate-1) | The [Predicate](https://docs.microsoft.com/dotnet/api/system.predicate-1) delegate that defines the conditions of the element to search for. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The zero-based index of the last occurrence of an element that matches the conditions defined by *match* , if found; otherwise, –1.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *match* is null.

### ![](/files/hsR4ok3152WyAf8J2C1u) FindLastIndex(startIndex, match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the range of elements in the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1) that extends from the specified index to the last element.

| Parameter      | Type                                                                      | Description                                                                                                                                  |
| -------------- | ------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **startIndex** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)               | The zero-based starting index of the search.                                                                                                 |
| **match**      | [Predicate\<T>](https://docs.microsoft.com/dotnet/api/system.predicate-1) | The [Predicate](https://docs.microsoft.com/dotnet/api/system.predicate-1) delegate that defines the conditions of the element to search for. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The zero-based index of the last occurrence of an element that matches the conditions defined by *match* , if found; otherwise, –1.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *match* is null.
* [ArgumentOutOfRangeException](https://docs.microsoft.com/dotnet/api/system.argumentoutofrangeexception) *startIndex* is outside the range of valid indexes for the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

### ![](/files/hsR4ok3152WyAf8J2C1u) ForEach(action)

Performs the specified action on each element of the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

| Parameter  | Type                                                                | Description                                                                                                                                                                                   |
| ---------- | ------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **action** | [Action\<T>](https://docs.microsoft.com/dotnet/api/system.action-1) | The [Action](https://docs.microsoft.com/dotnet/api/system.action) delegate to perform on each element of the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1). |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *action* is null.

### ![](/files/hsR4ok3152WyAf8J2C1u) GetEnumerator()

Returns an enumerator that iterates through the synchronized collection.

**Returns:** [IEnumerator\<T>](https://docs.microsoft.com/dotnet/api/system.collections.generic.ienumerator-1). An [IEnumerator](https://docs.microsoft.com/dotnet/api/system.collections.generic.ienumerator-1) for objects of the type stored in the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) IndexOf(item)

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

| Parameter | Type                                                                                 | Description                            |
| --------- | ------------------------------------------------------------------------------------ | -------------------------------------- |
| **item**  | [T](/api/wisej.core/general/wisej.core.synchronizedlist-less-than-t-greater-than.md) | Removes all items from the collection. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The zero-based index of the first occurrence of the value in the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) Insert(index, item)

Inserts an item into the collection at a specified index.

| Parameter | Type                                                                                 | Description                                                              |
| --------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------ |
| **index** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)                          | The zero-based index of the element to be retrieved from the collection. |
| **item**  | [T](/api/wisej.core/general/wisej.core.synchronizedlist-less-than-t-greater-than.md) | The object to be inserted into the collection as an element.             |

**Throws:**

* [ArgumentOutOfRangeException](https://docs.microsoft.com/dotnet/api/system.argumentoutofrangeexception) The *index* specified is less than zero or greater than the number of items in the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) InsertRange(index, collection)

Inserts the elements of a collection into the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1) at the specified index.

| Parameter      | Type                                                                                              | Description                                                                                                                                                                                                                                      |
| -------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **index**      | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)                                       | The zero-based index at which the new elements should be inserted.                                                                                                                                                                               |
| **collection** | [IEnumerable\<T>](https://docs.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1) | The collection whose elements should be inserted into the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1). The collection itself cannot be null, but it can contain elements that are null, for reference types. |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *collection* is null.
* [ArgumentOutOfRangeException](https://docs.microsoft.com/dotnet/api/system.argumentoutofrangeexception) *index* is less than 0; or *index* is greater than [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

### ![](/files/hsR4ok3152WyAf8J2C1u) Remove(item)

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

| Parameter | Type                                                                                 | Description                               |
| --------- | ------------------------------------------------------------------------------------ | ----------------------------------------- |
| **item**  | [T](/api/wisej.core/general/wisej.core.synchronizedlist-less-than-t-greater-than.md) | The object to remove from the collection. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true if item was successfully removed from the collection; otherwise, false.

### ![](/files/hsR4ok3152WyAf8J2C1u) RemoveAll(match)

Removes all the elements that match the conditions defined by the specified predicate.

| Parameter | Type                                                                      | Description                                                                                                                               |
| --------- | ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| **match** | [Predicate\<T>](https://docs.microsoft.com/dotnet/api/system.predicate-1) | The [Predicate](https://docs.microsoft.com/dotnet/api/system.predicate-1) delegate that defines the conditions of the elements to remove. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The number of elements removed from the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1) .

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *match* is null.

### ![](/files/hsR4ok3152WyAf8J2C1u) RemoveAt(index)

Removes an item at a specified index from the collection.

| Parameter | Type                                                        | Description                                                              |
| --------- | ----------------------------------------------------------- | ------------------------------------------------------------------------ |
| **index** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32) | The zero-based index of the element to be retrieved from the collection. |

**Throws:**

* [ArgumentOutOfRangeException](https://docs.microsoft.com/dotnet/api/system.argumentoutofrangeexception) The *index* specified is less than zero or greater than the number of items in the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) Sort()

Sorts the elements in the entire [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1) using the default comparer.

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) The default comparer [Comparer](https://docs.microsoft.com/dotnet/api/system.collections.generic.comparer-1) cannot find an implementation of the [IComparable](https://docs.microsoft.com/dotnet/api/system.icomparable) generic interface or the [IComparable](https://docs.microsoft.com/dotnet/api/system.icomparable) interface for the type of the collection elements.

### ![](/files/hsR4ok3152WyAf8J2C1u) Sort(comparer)

Sorts the elements in the entire [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1) using the specified comparer.

| Parameter    | Type                                                                                          | Description                                                                                                                                                                                                                                                               |
| ------------ | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **comparer** | [IComparer\<T>](https://docs.microsoft.com/dotnet/api/system.collections.generic.icomparer-1) | The [IComparer](https://docs.microsoft.com/dotnet/api/system.collections.generic.icomparer-1) implementation to use when comparing elements, or null to use the default comparer [Comparer](https://docs.microsoft.com/dotnet/api/system.collections.generic.comparer-1). |

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) *comparer* is null, and the default comparer [Comparer](https://docs.microsoft.com/dotnet/api/system.collections.generic.comparer-1) cannot find implementation of the [IComparable](https://docs.microsoft.com/dotnet/api/system.icomparable) generic interface or the [IComparable](https://docs.microsoft.com/dotnet/api/system.icomparable) interface for the type of the collection elements.
* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception) The implementation of *comparer* caused an error during the sort. For example, *comparer* might not return 0 when comparing an item with itself.

### ![](/files/hsR4ok3152WyAf8J2C1u) Sort(comparison)

Sorts the elements in the entire [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1) using the specified [Comparison](https://docs.microsoft.com/dotnet/api/system.comparison-1).

| Parameter      | Type                                                                        | Description                                                                                                 |
| -------------- | --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| **comparison** | [Comparison\<T>](https://docs.microsoft.com/dotnet/api/system.comparison-1) | The [Comparison](https://docs.microsoft.com/dotnet/api/system.comparison-1) to use when comparing elements. |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *comparison* is null.
* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception) The implementation of *comparison* caused an error during the sort. For example, *comparison* might not return 0 when comparing an item with itself.

### ![](/files/hsR4ok3152WyAf8J2C1u) Sort(comparer, swapCallback)

Sorts the elements in the entire [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1) using the specified comparer and a related [IList](https://docs.microsoft.com/dotnet/api/system.collections.ilist) to sort in sync with this collection.

| Parameter                                         | Type                                                                                          | Description                                                                                                                                                                                                                                                               |
| ------------------------------------------------- | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **comparer**                                      | [IComparer\<T>](https://docs.microsoft.com/dotnet/api/system.collections.generic.icomparer-1) | The [IComparer](https://docs.microsoft.com/dotnet/api/system.collections.generic.icomparer-1) implementation to use when comparing elements, or null to use the default comparer [Comparer](https://docs.microsoft.com/dotnet/api/system.collections.generic.comparer-1). |
| **swapCallback** ![](/files/1vGqtbG2j637vQ4ROWOf) | [Func\<Int32, Int32, Boolean>](https://docs.microsoft.com/dotnet/api/system.func-3)           | An optional callback method, invoked on every swap. If the callback returns true to indicate that it handled the swap, the default swap is not performed.                                                                                                                 |

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) *comparer* is null, and the default comparer [Comparer](https://docs.microsoft.com/dotnet/api/system.collections.generic.comparer-1) cannot find implementation of the [IComparable](https://docs.microsoft.com/dotnet/api/system.icomparable) generic interface or the [IComparable](https://docs.microsoft.com/dotnet/api/system.icomparable) interface for the type of the collection elements.
* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception) The implementation of *comparer* caused an error during the sort. For example, *comparer* might not return 0 when comparing an item with itself.

### ![](/files/hsR4ok3152WyAf8J2C1u) Sum(selector)

Computes the sum of the sequence of System.Int32 values that are obtained by invoking a transform function on each element of the list.

| Parameter    | Type                                                                   | Description                                    |
| ------------ | ---------------------------------------------------------------------- | ---------------------------------------------- |
| **selector** | [Func\<T, Int32>](https://docs.microsoft.com/dotnet/api/system.func-2) | A transform function to apply to each element. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The sum of the returned values.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *selector* is null.

### ![](/files/hsR4ok3152WyAf8J2C1u) Sum(selector)

Computes the sum of the sequence of System.Int64 values that are obtained by invoking a transform function on each element of the list.

| Parameter    | Type                                                                   | Description                                    |
| ------------ | ---------------------------------------------------------------------- | ---------------------------------------------- |
| **selector** | [Func\<T, Int64>](https://docs.microsoft.com/dotnet/api/system.func-2) | A transform function to apply to each element. |

**Returns:** [Int64](https://docs.microsoft.com/dotnet/api/system.int64). The sum of the returned values.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *selector* is null.

### ![](/files/hsR4ok3152WyAf8J2C1u) Sum(selector)

Computes the sum of the sequence of System.Single values that are obtained by invoking a transform function on each element of the list.

| Parameter    | Type                                                                    | Description                                    |
| ------------ | ----------------------------------------------------------------------- | ---------------------------------------------- |
| **selector** | [Func\<T, Single>](https://docs.microsoft.com/dotnet/api/system.func-2) | A transform function to apply to each element. |

**Returns:** [Single](https://docs.microsoft.com/dotnet/api/system.single). The sum of the returned values.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *selector* is null.

### ![](/files/hsR4ok3152WyAf8J2C1u) Sum(selector)

Computes the sum of the sequence of System.Double values that are obtained by invoking a transform function on each element of the list.

| Parameter    | Type                                                                    | Description                                    |
| ------------ | ----------------------------------------------------------------------- | ---------------------------------------------- |
| **selector** | [Func\<T, Double>](https://docs.microsoft.com/dotnet/api/system.func-2) | A transform function to apply to each element. |

**Returns:** [Double](https://docs.microsoft.com/dotnet/api/system.double). The sum of the returned values.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *selector* is null.

### ![](/files/hsR4ok3152WyAf8J2C1u) Sum(selector)

Computes the sum of the sequence of System.Decimal values that are obtained by invoking a transform function on each element of the list.

| Parameter    | Type                                                                     | Description                                    |
| ------------ | ------------------------------------------------------------------------ | ---------------------------------------------- |
| **selector** | [Func\<T, Decimal>](https://docs.microsoft.com/dotnet/api/system.func-2) | A transform function to apply to each element. |

**Returns:** [Decimal](https://docs.microsoft.com/dotnet/api/system.decimal). The sum of the returned values.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *selector* is null.

### ![](/files/hsR4ok3152WyAf8J2C1u) ToArray()

Copies the elements of the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1) to a new array.

**Returns:** [T\[\]](/api/wisej.core/general/wisej.core.synchronizedlist-less-than-t-greater-than.md). An array containing copies of the elements of the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1).

### ![](/files/hsR4ok3152WyAf8J2C1u) TrimExcess()

Sets the capacity to the actual number of elements in the [List](https://docs.microsoft.com/dotnet/api/system.collections.generic.list-1), if that number is less than a threshold value.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/api/wisej.core/general/wisej.core.synchronizedlist-less-than-t-greater-than.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
