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>, int)
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
- bool
- trueif the specified- indexis within the range of the- list; otherwise,- false.
Type Parameters
- T
- The type of elements in the IList<T>. 
Exceptions
- ArgumentNullException
- listis null.
Next<T>(IList<T>, int)
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
- listIList<T>
- The IList<T> to extend. 
- indexint
- The index of which to advance to the next element from. 
Returns
- T
- default(TSource) if - indexis equal or greater than Count; otherwise the next element of- listrelative to- index.
Type Parameters
- T
- The type of elements in the IList<T>. 
Exceptions
- ArgumentNullException
- listis null.
- ArgumentOutOfRangeException
- indexis less than 0.
Previous<T>(IList<T>, int)
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
- listIList<T>
- The IList<T> to extend. 
- indexint
- The index of which to advance to the previous element from. 
Returns
- T
- default(TSource) if - indexis equal, greater or lower than Count; otherwise the previous element of- listrelative to- index.
Type Parameters
- T
- The type of elements in the IList<T>. 
Exceptions
- ArgumentNullException
- listis null.
- ArgumentOutOfRangeException
- indexis less than 0.
Remove<T>(IList<T>, Func<T, bool>)
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
- listIList<T>
- The IList<T> to extend. 
- predicateFunc<T, bool>
- The function delegate that defines the conditions of the element to remove. 
Returns
- bool
- trueif item was successfully removed from the- list,- falseotherwise.
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
- bool
- trueif the item was added to the- listsuccessfully,- falseotherwise.
Type Parameters
- T
Remarks
This method will add the specified item to the list if it is not already present.