Class ListExtensions
- 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
Returns
- Boolean
true
if the specifiedindex
is within the range of thelist
; 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
Int32The 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 oflist
relative toindex
.
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
Int32The 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 oflist
relative toindex
.
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 thelist
,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
Returns
- Boolean
true
if the item was added to thelist
successfully,false
otherwise.
Type Parameters
T
Remarks
This method will add the specified item
to the list if it is not already present.