In This Article

ListExtensions Class

Provides extension methods for the IList<T> type.

public static class ListExtensions
Inheritance:
object object

Methods

AddRange<T>(IList<T>, IEnumerable<T>)

Adds the elements of the specified collection to the end of the List<T>.

public static void AddRange<T>(this IList<T> list, IEnumerable<T> collection)
Type Parameters:
T -
Parameter Type Description
list IList<T>
collection IEnumerable<T>

The collection whose elements should be added to the end of the List<T>. The collection itself cannot be null, but it can contain elements that are null, if type T is a reference type.

Exceptions

Type Condition
ArgumentNullException

collection is null.

InsertRange<T>(IList<T>, int, IEnumerable<T>)

Inserts the elements of a collection into the List<T> at the specified index.

public static void InsertRange<T>(this IList<T> list, int index, IEnumerable<T> collection)
Type Parameters:
T -
Parameter Type Description
list IList<T>
index int

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

collection IEnumerable<T>

The collection whose elements should be inserted into the List<T>. The collection itself cannot be null, but it can contain elements that are null, if type T is a reference type.

Exceptions

Type Condition
ArgumentNullException

collection is null.

ArgumentOutOfRangeException
   <code class="paramref">index</code> is less than 0.  

-or-

index is greater than Count.

RemoveAll<T>(IList<T>, Predicate<T>)

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

public static int RemoveAll<T>(this IList<T> list, Predicate<T> match)
Type Parameters:
T -
Parameter Type Description
list IList<T>
match Predicate<T>

The Predicate<T> delegate that defines the conditions of the elements to remove.

Returns

int:

The number of elements removed from the List<T>.

Exceptions

Type Condition
ArgumentNullException

match is null.

Inherited Members