Class ListExtensions
Extension methods for
Inheritance
Namespace: X10D.Collections
Assembly: X10D.dll
Syntax
public static class ListExtensions : object
Methods
| Improve this Doc View SourceFill<T>(IList<T>, T)
Assigns the given value to each element of the list.
Declaration
public static void Fill<T>(this IList<T> source, T value)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | source | The list to be filled. |
T | value | The value to assign to each list element. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements in the list. |
Fill<T>(IList<T>, T, Int32, Int32)
Assigns the given value to the elements of the list which are within the range of startIndex
(inclusive) and the next count
number of indices.
Declaration
public static void Fill<T>(this IList<T> source, T value, int startIndex, int count)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | source | The list to be filled. |
T | value | The value to assign to each list element. |
System.Int32 | startIndex | A 32-bit integer that represents the index in the list at which filling begins. |
System.Int32 | count | The number of elements to fill. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements in the list. |
IndexOf<T>(IReadOnlyList<T>, T)
Searches for the specified object and returns the zero-based index of the first occurrence within the entire
Declaration
public static int IndexOf<T>(this IReadOnlyList<T> source, T item)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<T> | source | The list to search |
T | item | The object to locate in the |
Returns
Type | Description |
---|---|
System.Int32 | The zero-based index of the first occurrence of item within the entire |
Type Parameters
Name | Description |
---|---|
T | The type of elements in |
IndexOf<T>(IReadOnlyList<T>, T, Int32)
Searches for the specified object and returns the zero-based index of the first occurrence within the range of
elements in the
Declaration
public static int IndexOf<T>(this IReadOnlyList<T> source, T item, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<T> | source | The list to search |
T | item | The object to locate in the |
System.Int32 | startIndex | The zero-based starting index of the search. 0 (zero) is valid in an empty list. |
Returns
Type | Description |
---|---|
System.Int32 | The zero-based index of the first occurrence of item within the range of elements in the
|
Type Parameters
Name | Description |
---|---|
T | The type of elements in |
IndexOf<T>(IReadOnlyList<T>, T, Int32, Int32)
Searches for the specified object and returns the zero-based index of the first occurrence within the range of
elements in the
Declaration
public static int IndexOf<T>(this IReadOnlyList<T> source, T item, int startIndex, int count)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<T> | source | The list to search |
T | item | The object to locate in the |
System.Int32 | startIndex | The zero-based starting index of the search. 0 (zero) is valid in an empty list. |
System.Int32 | count | The number of elements in the section to search. |
Returns
Type | Description |
---|---|
System.Int32 | The zero-based index of the first occurrence of item within the range of elements in the
|
Type Parameters
Name | Description |
---|---|
T | The type of elements in |
Random<T>(IReadOnlyList<T>, Nullable<Random>)
Returns a random element from the current list using a specified
Declaration
public static T Random<T>(this IReadOnlyList<T> source, Random? random = null)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<T> | source | The source collection from which to draw. |
System.Nullable<Random> | random | The |
Returns
Type | Description |
---|---|
T | A random element of type |
Type Parameters
Name | Description |
---|---|
T | The element type. |
Examples
var list = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var number = list.Random();
|
Improve this Doc
View Source
RemoveRange<T>(IList<T>, Range)
Removes a range of elements from the list.
Declaration
public static void RemoveRange<T>(this IList<T> source, Range range)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | source | The list whose elements to remove. |
Range | range | The range of elements to remove. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements in |
Shuffle<T>(IList<T>, Nullable<Random>)
Reorganizes the elements in a list by implementing a Fisher-Yates shuffle.
Declaration
public static void Shuffle<T>(this IList<T> source, Random? random = null)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | source | The |
System.Nullable<Random> | random | The |
Type Parameters
Name | Description |
---|---|
T | The element type. |
Slice<T>(IReadOnlyList<T>, Int32)
Forms a slice out of the current list that begins at a specified index.
Declaration
public static IReadOnlyList<T> Slice<T>(this IReadOnlyList<T> source, int start)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<T> | source | The list to slice. |
System.Int32 | start | The index at which to begin the slice. |
Returns
Type | Description |
---|---|
IReadOnlyList<T> | A list that consists of all elements of the current list from |
Type Parameters
Name | Description |
---|---|
T | The type of elements in |
Slice<T>(IReadOnlyList<T>, Int32, Int32)
Forms a slice out of the current list that begins at a specified index for a specified length.
Declaration
public static IReadOnlyList<T> Slice<T>(this IReadOnlyList<T> source, int start, int length)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<T> | source | The list to slice. |
System.Int32 | start | The index at which to begin the slice. |
System.Int32 | length | The desired length for the slice. |
Returns
Type | Description |
---|---|
IReadOnlyList<T> | A list that consists of all elements of the current list from |
Type Parameters
Name | Description |
---|---|
T | The type of elements in |
Swap<T>(IList<T>, IList<T>)
Swaps all elements in a list with the elements in another list.
Declaration
public static void Swap<T>(this IList<T> source, IList<T> other)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | source | The first list. |
IList<T> | other | The second list. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements in |