Class List
Provides various extensions for IList<T> interface.
Inherited Members
Namespace: DotNext.Collections.Generic
Assembly: DotNext.dll
Syntax
public static class List
Methods
| Improve this Doc View SourceConvert<TInput, TOutput>(IReadOnlyList<TInput>, ValueFunc<TInput, TOutput>)
Returns lazily converted read-only list.
Declaration
public static ReadOnlyListView<TInput, TOutput> Convert<TInput, TOutput>(this IReadOnlyList<TInput> list, in ValueFunc<TInput, TOutput> converter)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<TInput> | list | Read-only list to convert. |
ValueFunc<TInput, TOutput> | converter | A list item conversion function. |
Returns
Type | Description |
---|---|
ReadOnlyListView<TInput, TOutput> | Lazily converted read-only list. |
Type Parameters
Name | Description |
---|---|
TInput | Type of items in the source list. |
TOutput | Type of items in the target list. |
Convert<TInput, TOutput>(IReadOnlyList<TInput>, Converter<TInput, TOutput>)
Returns lazily converted read-only list.
Declaration
public static ReadOnlyListView<TInput, TOutput> Convert<TInput, TOutput>(this IReadOnlyList<TInput> list, Converter<TInput, TOutput> converter)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<TInput> | list | Read-only list to convert. |
Converter<TInput, TOutput> | converter | A list item conversion function. |
Returns
Type | Description |
---|---|
ReadOnlyListView<TInput, TOutput> | Lazily converted read-only list. |
Type Parameters
Name | Description |
---|---|
TInput | Type of items in the source list. |
TOutput | Type of items in the target list. |
IndexerGetter<T>(IList<T>)
Returns System.Collections.Generic.IList`1.get_Item(System.Int32) as delegate attached to the list instance.
Declaration
public static Func<int, T> IndexerGetter<T>(this IList<T> list)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | list | Mutable list instance. |
Returns
Type | Description |
---|---|
Func<Int32, T> | A delegate representing indexer. |
Type Parameters
Name | Description |
---|---|
T | Type of list items. |
IndexerGetter<T>(IReadOnlyList<T>)
Returns System.Collections.Generic.IReadOnlyList`1.get_Item(System.Int32) as delegate attached to the list instance.
Declaration
public static Func<int, T> IndexerGetter<T>(this IReadOnlyList<T> list)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<T> | list | Read-only list instance. |
Returns
Type | Description |
---|---|
Func<Int32, T> | A delegate representing indexer. |
Type Parameters
Name | Description |
---|---|
T | Type of list items. |
IndexerSetter<T>(IList<T>)
Returns System.Collections.Generic.IList`1.set_Item(System.Int32,`0) as delegate attached to the list instance.
Declaration
public static Action<int, T> IndexerSetter<T>(this IList<T> list)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | list | Mutable list instance. |
Returns
Type | Description |
---|---|
Action<Int32, T> | A delegate representing indexer. |
Type Parameters
Name | Description |
---|---|
T | Type of list items. |
Insert<T>(IList<T>, Index, T)
Inserts an item to the list at the specified index.
Declaration
public static void Insert<T>(this IList<T> list, Index index, T item)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | list | The list to modify. |
Index | index | The zero-based index at which item should be inserted. |
T | item | The object to insert into the list. |
Type Parameters
Name | Description |
---|---|
T | The type of elements in the list. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
NotSupportedException |
|
InsertOrdered<T>(IList<T>, T, ValueFunc<T, T, Int32>)
Inserts the item into sorted list.
Declaration
public static int InsertOrdered<T>(this IList<T> list, T item, in ValueFunc<T, T, int> comparer)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | list | The list to insert into. |
T | item | The item to be added into the list. |
ValueFunc<T, T, Int32> | comparer | The comparer function. |
Returns
Type | Description |
---|---|
Int32 | The actual index of the inserted item. |
Type Parameters
Name | Description |
---|---|
T | The type of the items in the list. |
Remarks
Time complexity of this operation is O(log N), where N is a size of the list.
InsertOrdered<T>(IList<T>, T, Comparison<T>)
Inserts the item into sorted list.
Declaration
public static int InsertOrdered<T>(this IList<T> list, T item, Comparison<T> comparer)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | list | The list to insert into. |
T | item | The item to be added into the list. |
Comparison<T> | comparer | The comparer function. |
Returns
Type | Description |
---|---|
Int32 | The actual index of the inserted item. |
Type Parameters
Name | Description |
---|---|
T | The type of the items in the list. |
Remarks
Time complexity of this operation is O(log N), where N is a size of the list.
RemoveAt<T>(IList<T>, Index)
Removes the item at the specifie index.
Declaration
public static void RemoveAt<T>(this IList<T> list, Index index)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | list | The list to modify. |
Index | index | The zero-based index of the item to remove. |
Type Parameters
Name | Description |
---|---|
T | The type of elements in the list. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
NotSupportedException |
|
RemoveRange<T>(List<T>, Range)
Removes a range of elements from list.
Declaration
public static void RemoveRange<T>(this List<T> list, Range range)
Parameters
Type | Name | Description |
---|---|---|
List<T> | list | The list to modify. |
Range | range | The range of elements to be removed. |
Type Parameters
Name | Description |
---|---|
T | The type of elements in the list. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
Singleton<T>(T)
Constructs read-only list with single item in it.
Declaration
public static IReadOnlyList<T> Singleton<T>(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | An item to be placed into list. |
Returns
Type | Description |
---|---|
IReadOnlyList<T> | Read-only list containing single item. |
Type Parameters
Name | Description |
---|---|
T | Type of list items. |
Slice<T>(IList<T>, Range)
Returns slice of the list.
Declaration
public static ListSegment<T> Slice<T>(this IList<T> list, Range range)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | list | The list of elements. |
Range | range | The range of elements in the list. |
Returns
Type | Description |
---|---|
ListSegment<T> | The section of the list. |
Type Parameters
Name | Description |
---|---|
T | The type of elements in the list. |
ToArray<TInput, TOutput>(IList<TInput>, ValueFunc<TInput, TOutput>)
Converts list into array and perform mapping for each element.
Declaration
public static TOutput[] ToArray<TInput, TOutput>(this IList<TInput> input, in ValueFunc<TInput, TOutput> mapper)
Parameters
Type | Name | Description |
---|---|---|
IList<TInput> | input | A list to convert. Cannot be null. |
ValueFunc<TInput, TOutput> | mapper | Element mapping function. |
Returns
Type | Description |
---|---|
TOutput[] | An array of list items. |
Type Parameters
Name | Description |
---|---|
TInput | Type of elements in the list. |
TOutput | Type of elements in the output array. |
ToArray<TInput, TOutput>(IList<TInput>, ValueFunc<Int32, TInput, TOutput>)
Converts list into array and perform mapping for each element.
Declaration
public static TOutput[] ToArray<TInput, TOutput>(this IList<TInput> input, in ValueFunc<int, TInput, TOutput> mapper)
Parameters
Type | Name | Description |
---|---|---|
IList<TInput> | input | A list to convert. Cannot be null. |
ValueFunc<Int32, TInput, TOutput> | mapper | Index-aware element mapping function. |
Returns
Type | Description |
---|---|
TOutput[] | An array of list items. |
Type Parameters
Name | Description |
---|---|
TInput | Type of elements in the list. |
TOutput | Type of elements in the output array. |
ToArray<TInput, TOutput>(IList<TInput>, Converter<TInput, TOutput>)
Converts list into array and perform mapping for each element.
Declaration
public static TOutput[] ToArray<TInput, TOutput>(this IList<TInput> input, Converter<TInput, TOutput> mapper)
Parameters
Type | Name | Description |
---|---|---|
IList<TInput> | input | A list to convert. Cannot be null. |
Converter<TInput, TOutput> | mapper | Element mapping function. |
Returns
Type | Description |
---|---|
TOutput[] | An array of list items. |
Type Parameters
Name | Description |
---|---|
TInput | Type of elements in the list. |
TOutput | Type of elements in the output array. |
ToArray<TInput, TOutput>(IList<TInput>, Func<Int32, TInput, TOutput>)
Converts list into array and perform mapping for each element.
Declaration
public static TOutput[] ToArray<TInput, TOutput>(this IList<TInput> input, Func<int, TInput, TOutput> mapper)
Parameters
Type | Name | Description |
---|---|---|
IList<TInput> | input | A list to convert. Cannot be null. |
Func<Int32, TInput, TOutput> | mapper | Index-aware element mapping function. |
Returns
Type | Description |
---|---|
TOutput[] | An array of list items. |
Type Parameters
Name | Description |
---|---|
TInput | Type of elements in the list. |
TOutput | Type of elements in the output array. |