Table of Contents

Class ListExtensions

Namespace
Garyon.Extensions
Assembly
Garyon.dll

Provides extension methods for the List<T> class.

public static class ListExtensions
Inheritance
ListExtensions
Inherited Members

Methods

Clone<T>(List<List<T>>)

Clones a list of lists.

public static List<List<T>> Clone<T>(this List<List<T>> l)

Parameters

l List<List<T>>

The list of lists to clone.

Returns

List<List<T>>

Type Parameters

T

The type of the list elements.

InsertAtStart<T>(List<T>, T)

Inserts an element at the start of the List<T>.

public static List<T> InsertAtStart<T>(this List<T> l, T element)

Parameters

l List<T>

The List<T> at whose start to insert the element.

element T

The element to add.

Returns

List<T>

The instance of the List<T> in which the new element was inserted.

Type Parameters

T

The type of the elements contained in the List<T>.

MoveElementToEnd<T>(List<T>, int)

Moves an element to the end of the List<T>.

public static List<T> MoveElementToEnd<T>(this List<T> l, int from)

Parameters

l List<T>

The List<T> within which to move an element.

from int

The index of the element to move.

Returns

List<T>

The instance of the List<T> in which the element was moved.

Type Parameters

T

The type of the elements contained in the List<T>.

MoveElementToStart<T>(List<T>, int)

Moves an element to the start of the List<T>.

public static List<T> MoveElementToStart<T>(this List<T> l, int from)

Parameters

l List<T>

The List<T> within which to move an element.

from int

The index of the element to move.

Returns

List<T>

The instance of the List<T> in which the element was moved.

Type Parameters

T

The type of the elements contained in the List<T>.

MoveElement<T>(List<T>, int, int)

Moves an element in the List<T> to a different position.

public static List<T> MoveElement<T>(this List<T> l, int from, int to)

Parameters

l List<T>

The List<T> within which to move an element.

from int

The index of the element to move.

to int

The new index of the element.

Returns

List<T>

The instance of the List<T> in which the element was moved.

Type Parameters

T

The type of the elements contained in the List<T>.

RemoveRange<T>(List<T>, IEnumerable<T>)

Removes a collection of elements from a list and returns a new list that does not contain the removed elements.

public static List<T> RemoveRange<T>(this List<T> l, IEnumerable<T> elements)

Parameters

l List<T>

The list whose elements to remove.

elements IEnumerable<T>

The elements to remove.

Returns

List<T>

A new copy of the list that does not contain the removed elements.

Type Parameters

T

The type of the elements that are stored in the list.

RemoveRange<T>(List<T>, IEnumerable<T>, out int)

Removes a collection of elements from a list and returns a new list that does not contain the removed elements.

public static List<T> RemoveRange<T>(this List<T> l, IEnumerable<T> elements, out int removedElements)

Parameters

l List<T>

The list whose elements to remove.

elements IEnumerable<T>

The elements to remove.

removedElements int

The number of elements that were removed from the list.

Returns

List<T>

A new copy of the list that does not contain the removed elements.

Type Parameters

T

The type of the elements that are stored in the list.

SetEnsureCapacity<T>(List<T>, int, T)

Sets an element to the list at the specified index, by extending the list if the count is insufficient.

public static void SetEnsureCapacity<T>(this List<T> list, int index, T element)

Parameters

list List<T>

The list on which to set the element at the specified index.

index int

The index at which to set the element.

element T

The element to set.

Type Parameters

T

The element type.