Table of Contents

Class ListExtensions

Namespace
Cuemon.Extensions.Collections.Generic
Assembly
Cuemon.Extensions.Collections.Generic.dll

Extension methods for the IList<T> interface.

public static class ListExtensions
Inheritance
ListExtensions

Methods

HasIndex<T>(IList<T>, Int32)

Determines whether the list of the IList<T> is within the range of the index.

public static bool HasIndex<T>(this IList<T> list, int index)

Parameters

list IList<T>

The IList<T> to extend.

index Int32

The index to find.

Returns

Boolean

true if the specified index is within the range of the list; otherwise, false.

Type Parameters

T

The type of elements in the IList<T>.

Exceptions

ArgumentNullException

list is null.

Next<T>(IList<T>, Int32)

Returns the next element of list relative to index, or the last element of list if index is equal or greater than Count.

public static T Next<T>(this IList<T> list, int index)

Parameters

list IList<T>

The IList<T> to extend.

index Int32

The index of which to advance to the next element from.

Returns

T

default(TSource) if index is equal or greater than Count; otherwise the next element of list relative to index.

Type Parameters

T

The type of elements in the IList<T>.

Exceptions

ArgumentNullException

list is null.

ArgumentOutOfRangeException

index is less than 0.

Previous<T>(IList<T>, Int32)

Returns the previous element of list relative to index, or the first or last element of list if index is equal, greater or lower than Count.

public static T Previous<T>(this IList<T> list, int index)

Parameters

list IList<T>

The IList<T> to extend.

index Int32

The index of which to advance to the previous element from.

Returns

T

default(TSource) if index is equal, greater or lower than Count; otherwise the previous element of list relative to index.

Type Parameters

T

The type of elements in the IList<T>.

Exceptions

ArgumentNullException

list is null.

ArgumentOutOfRangeException

index is less than 0.

Remove<T>(IList<T>, Func<T, Boolean>)

Removes the first occurrence of a specific object from the list.

public static bool Remove<T>(this IList<T> list, Func<T, bool> predicate)

Parameters

list IList<T>

The IList<T> to extend.

predicate Func<T, Boolean>

The function delegate that defines the conditions of the element to remove.

Returns

Boolean

true if item was successfully removed from the list, false otherwise.

Type Parameters

T

The type of elements in the IList<T>.

TryAdd<T>(IList<T>, T)

Attempts to add the specified item to the list.

public static bool TryAdd<T>(this IList<T> list, T item)

Parameters

list IList<T>

The IList<T> to extend.

item T

The item to add.

Returns

Boolean

true if the item was added to the list successfully, false otherwise.

Type Parameters

T

Remarks

This method will add the specified item to the list if it is not already present.