Show / Hide Table of Contents

Class List

Provides various extensions for IList<T> interface.

Inheritance
object
List
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: DotNext.Collections.Generic
Assembly: DotNext.dll
Syntax
public static class List

Methods

| Edit this page View Source

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.

| Edit this page View Source

IndexerGetter<T>(IList<T>)

Returns this[int].get 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<int, T>

A delegate representing indexer.

Type Parameters
Name Description
T

Type of list items.

| Edit this page View Source

IndexerGetter<T>(IReadOnlyList<T>)

Returns this[int].get 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<int, T>

A delegate representing indexer.

Type Parameters
Name Description
T

Type of list items.

| Edit this page View Source

IndexerSetter<T>(IList<T>)

Returns this[int].set 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<int, T>

A delegate representing indexer.

Type Parameters
Name Description
T

Type of list items.

| Edit this page View Source

InsertOrdered<T>(IList<T>, T, delegate*<T?, T?, int>)

Inserts the item into sorted list.

Declaration
[CLSCompliant(false)]
public static int InsertOrdered<T>(this IList<T> list, T item, delegate*<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.

delegate*<T, T, int> comparer

The comparer function.

Returns
Type Description
int

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.

| Edit this page View Source

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
int

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.

| Edit this page View Source

InsertOrdered<T, TComparer>(IList<T>, T, TComparer)

Inserts the item into sorted list.

Declaration
public static int InsertOrdered<T, TComparer>(this IList<T> list, T item, TComparer comparer) where TComparer : IComparer<T>
Parameters
Type Name Description
IList<T> list

The list to insert into.

T item

The item to be added into the list.

TComparer comparer

The comparer function.

Returns
Type Description
int

The actual index of the inserted item.

Type Parameters
Name Description
T

The type of the items in the list.

TComparer

The type of the comparer providing comparison logic.

Remarks

Time complexity of this operation is O(log N), where N is a size of the list.

| Edit this page View Source

InsertOrdered<T, TComparer>(List<T>, T, TComparer)

Inserts the item into sorted list.

Declaration
public static int InsertOrdered<T, TComparer>(this List<T> list, T item, TComparer comparer) where TComparer : IComparer<T>
Parameters
Type Name Description
List<T> list

The list to insert into.

T item

The item to be added into the list.

TComparer comparer

The comparer function.

Returns
Type Description
int

The actual index of the inserted item.

Type Parameters
Name Description
T

The type of the items in the list.

TComparer

The type of the comparer providing comparison logic.

Remarks

Time complexity of this operation is O(log N), where N is a size of the list. This version method is specially optimized for List<T> data type while InsertOrdered<T, TComparer>(IList<T>, T, TComparer) is for generic list of unknown type.

| Edit this page View Source

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

index is not a valid index in list.

NotSupportedException

list is read-only.

| Edit this page View Source

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

index is not a valid index in list.

NotSupportedException

list is read-only.

| Edit this page View Source

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

range is invalid.

| Edit this page View Source

Repeat<T>(T, int)

Generates a list that contains one repeated value.

Declaration
public static IReadOnlyList<T> Repeat<T>(T item, int count)
Parameters
Type Name Description
T item

The item to be returned from the list.

int count

The number of elements in the list.

Returns
Type Description
IReadOnlyList<T>

A list that contains a repeated value.

Type Parameters
Name Description
T

Type of the list.

Exceptions
Type Condition
ArgumentOutOfRangeException

count is negative.

| Edit this page View Source

Singleton<T>(T)

Constructs read-only list with a 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.

| Edit this page View Source

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.

| Edit this page View Source

ToArray<TInput, TOutput>(IList<TInput>, delegate*<int, TInput, TOutput>)

Converts list into array and perform mapping for each element.

Declaration
[CLSCompliant(false)]
public static TOutput[] ToArray<TInput, TOutput>(this IList<TInput> input, delegate*<int, TInput, TOutput> mapper)
Parameters
Type Name Description
IList<TInput> input

A list to convert. Cannot be null.

delegate*<int, 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.

| Edit this page View Source

ToArray<TInput, TOutput>(IList<TInput>, delegate*<int, TInput, TOutput>)

Converts list into array and perform mapping for each element.

Declaration
[CLSCompliant(false)]
public static TOutput[] ToArray<TInput, TOutput>(this IList<TInput> input, delegate*<int, TInput, TOutput> mapper)
Parameters
Type Name Description
IList<TInput> input

A list to convert. Cannot be null.

delegate*<int, 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.

| Edit this page View Source

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.

| Edit this page View Source

ToArray<TInput, TOutput>(IList<TInput>, Func<int, 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<int, 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.

  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾