Class ListExtensions
- Namespace
- CarinaStudio.Collections
- Assembly
- CarinaStudio.AppBase.Core.dll
public static class ListExtensions
- Inheritance
-
ListExtensions
- Inherited Members
Methods
AsReadOnly<T>(IList<T>)
public static IList<T> AsReadOnly<T>(this IList<T> list)
Parameters
Returns
- IList<T>
Read-only IList<T>, the instance also implements IReadOnlyList<T>.
Type Parameters
TType of element.
Remarks
If list implements INotifyCollectionChanged then returned IList<T> will also implements INotifyCollectionChanged.
BinarySearch<T>(IList<T>, T)
Use binary-search to find given element.
public static int BinarySearch<T>(this IList<T> list, T element) where T : IComparable<T>
Parameters
listIList<T>List to find element.
elementTElement to be found.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
TType of element.
BinarySearch<T>(IList<T>, T, IComparer<T>)
Use binary-search to find given element.
public static int BinarySearch<T>(this IList<T> list, T element, IComparer<T> comparer)
Parameters
listIList<T>List to find element.
elementTElement to be found.
comparerIComparer<T>IComparer<T> to compare elements.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
TType of element.
BinarySearch<T>(IList<T>, T, Comparison<T>)
Use binary-search to find given element.
public static int BinarySearch<T>(this IList<T> list, T element, Comparison<T> comparison)
Parameters
listIList<T>List to find element.
elementTElement to be found.
comparisonComparison<T>Comparison function.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
TType of element.
BinarySearch<T>(IReadOnlyList<T>, T)
Use binary-search to find given element.
public static int BinarySearch<T>(this IReadOnlyList<T> list, T element) where T : IComparable<T>
Parameters
listIReadOnlyList<T>List to find element.
elementTElement to be found.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
TType of element.
BinarySearch<T>(IReadOnlyList<T>, T, IComparer<T>)
Use binary-search to find given element.
public static int BinarySearch<T>(this IReadOnlyList<T> list, T element, IComparer<T> comparer)
Parameters
listIReadOnlyList<T>List to find element.
elementTElement to be found.
comparerIComparer<T>IComparer<T> to compare elements.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
TType of element.
BinarySearch<T>(IReadOnlyList<T>, T, Comparison<T>)
Use binary-search to find given element.
public static int BinarySearch<T>(this IReadOnlyList<T> list, T element, Comparison<T> comparison)
Parameters
listIReadOnlyList<T>List to find element.
elementTElement to be found.
comparisonComparison<T>Comparison function.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
TType of element.
BinarySearch<T, TKey>(IList<T>, TKey, Func<T, TKey>)
Use binary-search to find given element by key.
public static int BinarySearch<T, TKey>(this IList<T> list, TKey key, Func<T, TKey> keyGetter) where TKey : IComparable<TKey>
Parameters
listIList<T>List to find element.
keyTKeyKey of element to be found.
keyGetterFunc<T, TKey>Method to get key from element.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
TType of element.
TKeyType of key of element.
BinarySearch<T, TKey>(IList<T>, TKey, Func<T, TKey>, Comparison<TKey>)
Use binary-search to find given element by key.
public static int BinarySearch<T, TKey>(this IList<T> list, TKey key, Func<T, TKey> keyGetter, Comparison<TKey> comparison)
Parameters
listIList<T>List to find element.
keyTKeyKey of element to be found.
keyGetterFunc<T, TKey>Method to get key from element.
comparisonComparison<TKey>Comparison function.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
TType of element.
TKeyType of key of element.
BinarySearch<T, TKey>(IReadOnlyList<T>, TKey, Func<T, TKey>)
Use binary-search to find given element by key.
public static int BinarySearch<T, TKey>(this IReadOnlyList<T> list, TKey key, Func<T, TKey> keyGetter) where TKey : IComparable<TKey>
Parameters
listIReadOnlyList<T>List to find element.
keyTKeyKey of element to be found.
keyGetterFunc<T, TKey>Method to get key from element.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
TType of element.
TKeyType of key of element.
BinarySearch<T, TKey>(IReadOnlyList<T>, TKey, Func<T, TKey>, Comparison<TKey>)
Use binary-search to find given element by key.
public static int BinarySearch<T, TKey>(this IReadOnlyList<T> list, TKey key, Func<T, TKey> keyGetter, Comparison<TKey> comparison)
Parameters
listIReadOnlyList<T>List to find element.
keyTKeyKey of element to be found.
keyGetterFunc<T, TKey>Method to get key from element.
comparisonComparison<TKey>Comparison function.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
TType of element.
TKeyType of key of element.
BinarySearch<T, TKey>(List<T>, TKey, Func<T, TKey>)
Use binary-search to find given element by key.
public static int BinarySearch<T, TKey>(this List<T> list, TKey key, Func<T, TKey> keyGetter) where TKey : IComparable<TKey>
Parameters
listList<T>List to find element.
keyTKeyKey of element to be found.
keyGetterFunc<T, TKey>Method to get key from element.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
TType of element.
TKeyType of key of element.
BinarySearch<T, TKey>(List<T>, TKey, Func<T, TKey>, Comparison<TKey>)
Use binary-search to find given element by key.
public static int BinarySearch<T, TKey>(this List<T> list, TKey key, Func<T, TKey> keyGetter, Comparison<TKey> comparison)
Parameters
listList<T>List to find element.
keyTKeyKey of element to be found.
keyGetterFunc<T, TKey>Method to get key from element.
comparisonComparison<TKey>Comparison function.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
TType of element.
TKeyType of key of element.
Cast<TOut>(IList)
Case given list to generic typed list.
public static IList<TOut> Cast<TOut>(this IList list)
Parameters
listIListList.
Returns
- IList<TOut>
Generic typed list.
Type Parameters
TOutType of element.
Remarks
If list implements INotifyCollectionChanged then returned IList<T> will also implements INotifyCollectionChanged.
CopyTo<T>(IList<T>, int, T[], int, int)
Copy elements to array.
public static void CopyTo<T>(this IList<T> list, int index, T[] array, int arrayIndex, int count)
Parameters
listIList<T>indexintIndex of first element in list to copy.
arrayT[]Array to place copied elements.
arrayIndexintIndex of first position in
arrayto place copied elements.countintNumber of elements to copy.
Type Parameters
TType of list element.
CopyTo<T>(IReadOnlyList<T>, int, T[], int, int)
Copy elements to array.
public static void CopyTo<T>(this IReadOnlyList<T> list, int index, T[] array, int arrayIndex, int count)
Parameters
listIReadOnlyList<T>indexintIndex of first element in list to copy.
arrayT[]Array to place copied elements.
arrayIndexintIndex of first position in
arrayto place copied elements.countintNumber of elements to copy.
Type Parameters
TType of list element.
CopyTo<T>(List<T>, int, T[], int, int)
Copy elements to array.
public static void CopyTo<T>(this List<T> list, int index, T[] array, int arrayIndex, int count)
Parameters
listList<T>The list.
indexintIndex of first element in list to copy.
arrayT[]Array to place copied elements.
arrayIndexintIndex of first position in
arrayto place copied elements.countintNumber of elements to copy.
Type Parameters
TType of list element.
Remarks
The method is available for target framework before .NET 9.
GetRangeView<T>(IList<T>, int, int)
Get read-only view of range of source list which allows accessing elements from source list directly without copying.
public static IList<T> GetRangeView<T>(this IList<T> list, int start, int count)
Parameters
listIList<T>Source list.
startintStart index of range.
countintNumber of elements needed to be included.
Returns
- IList<T>
View of range of source list.
Type Parameters
TType of element.
Remarks
The element get from view and Count of view may be changed if source list has been modified.
GetRangeView<T>(IReadOnlyList<T>, int, int)
Get read-only view of range of source list which allows accessing elements from source list directly without copying.
public static IReadOnlyList<T> GetRangeView<T>(this IReadOnlyList<T> list, int start, int count)
Parameters
listIReadOnlyList<T>Source list.
startintStart index of range.
countintNumber of elements needed to be included.
Returns
- IReadOnlyList<T>
View of range of source list.
Type Parameters
TType of element.
Remarks
The element get from view and Count of view may be changed if source list has been modified.
GetRangeView<T>(List<T>, int, int)
Get read-only view of range of source list which allows accessing elements from source list directly without copying.
public static IList<T> GetRangeView<T>(this List<T> list, int start, int count)
Parameters
listList<T>Source list.
startintStart index of range.
countintNumber of elements needed to be included.
Returns
- IList<T>
View of range of source list.
Type Parameters
TType of element.
Remarks
The element get from view and Count of view may be changed if source list has been modified. The method is available for target framework before .NET 9. The method is available for target framework before .NET 9.
IsEmpty<T>(List<T>)
Check whether the given list is empty or not.
public static bool IsEmpty<T>(this List<T> list)
Parameters
listList<T>List to check.
Returns
- bool
True if the list is empty.
Type Parameters
TType of element of collection.
Remarks
The method is available for target framework before .NET 9.
IsNotEmpty<T>(List<T>?)
Check whether the given list is not empty or not.
public static bool IsNotEmpty<T>(this List<T>? list)
Parameters
listList<T>List to check.
Returns
- bool
True if the list is not empty.
Type Parameters
TType of element of collection.
Remarks
The method is available for target framework before .NET 9.
IsNullOrEmpty<T>(List<T>?)
Check whether given list is null/empty or not.
public static bool IsNullOrEmpty<T>(this List<T>? collection)
Parameters
collectionList<T>List to check.
Returns
- bool
True if the list is null or empty.
Type Parameters
TType of element of collection.
Remarks
The method is available for target framework before .NET 9.
IsSorted<T>(IList<T>)
Check whether elements in given IList<T> is sorted or not.
public static bool IsSorted<T>(this IList<T> list) where T : IComparable<T>
Parameters
Returns
Type Parameters
TType of elements.
IsSorted<T>(IList<T>, IComparer<T>)
Check whether elements in given IList<T> is sorted or not.
public static bool IsSorted<T>(this IList<T> list, IComparer<T> comparer)
Parameters
listIList<T>comparerIComparer<T>IComparer<T> to check order of elements.
Returns
Type Parameters
TType of elements.
IsSorted<T>(IList<T>, Comparison<T>)
Check whether elements in given IList<T> is sorted or not.
public static bool IsSorted<T>(this IList<T> list, Comparison<T> comparison)
Parameters
listIList<T>comparisonComparison<T>Comparison method to check order of elements.
Returns
Type Parameters
TType of elements.
IsSorted<T>(IReadOnlyList<T>)
Check whether elements in given IReadOnlyList<T> is sorted or not.
public static bool IsSorted<T>(this IReadOnlyList<T> list) where T : IComparable<T>
Parameters
listIReadOnlyList<T>
Returns
- bool
True if elements in IReadOnlyList<T> are sorted.
Type Parameters
TType of elements.
IsSorted<T>(IReadOnlyList<T>, IComparer<T>)
Check whether elements in given IReadOnlyList<T> is sorted or not.
public static bool IsSorted<T>(this IReadOnlyList<T> list, IComparer<T> comparer)
Parameters
listIReadOnlyList<T>comparerIComparer<T>IComparer<T> to check order of elements.
Returns
- bool
True if elements in IReadOnlyList<T> are sorted.
Type Parameters
TType of elements.
IsSorted<T>(IReadOnlyList<T>, Comparison<T>)
Check whether elements in given IReadOnlyList<T> is sorted or not.
public static bool IsSorted<T>(this IReadOnlyList<T> list, Comparison<T> comparison)
Parameters
listIReadOnlyList<T>comparisonComparison<T>Comparison method to check order of elements.
Returns
- bool
True if elements in IReadOnlyList<T> are sorted.
Type Parameters
TType of elements.
IsSorted<T>(List<T>)
Check whether elements in given list is sorted or not.
public static bool IsSorted<T>(this List<T> list) where T : IComparable<T>
Parameters
Returns
- bool
True if elements in the list are sorted.
Type Parameters
TType of elements.
Remarks
The method is available for target framework before .NET 9.
IsSorted<T>(List<T>, IComparer<T>)
Check whether elements in given list is sorted or not.
public static bool IsSorted<T>(this List<T> list, IComparer<T> comparer)
Parameters
listList<T>List.
comparerIComparer<T>IComparer<T> to check order of elements.
Returns
- bool
True if elements in the list are sorted.
Type Parameters
TType of elements.
Remarks
The method is available for target framework before .NET 9.
IsSorted<T>(List<T>, Comparison<T>)
Check whether elements in given IList<T> is sorted or not.
public static bool IsSorted<T>(this List<T> list, Comparison<T> comparison)
Parameters
listList<T>comparisonComparison<T>Comparison method to check order of elements.
Returns
Type Parameters
TType of elements.
Remarks
The method is available for target framework before .NET 9.
ReverseAsReadOnly<T>(IList<T>)
public static IList<T> ReverseAsReadOnly<T>(this IList<T> list)
Parameters
Returns
Type Parameters
TType of element.
Remarks
If list implements INotifyCollectionChanged then returned IList<T> will also implements INotifyCollectionChanged.
Reverse<T>(IList<T>)
public static IList<T> Reverse<T>(this IList<T> list)
Parameters
Returns
- IList<T>
Reversed IList<T>, the instance also implements IReadOnlyList<T>.
Type Parameters
TType of element.
Remarks
If list implements INotifyCollectionChanged then returned IList<T> will also implements INotifyCollectionChanged.
Reverse<T>(IReadOnlyList<T>)
Make given IReadOnlyList<T> as reversed IReadOnlyList<T>.
public static IReadOnlyList<T> Reverse<T>(this IReadOnlyList<T> list)
Parameters
listIReadOnlyList<T>IReadOnlyList<T> to be reversed.
Returns
- IReadOnlyList<T>
Reversed IReadOnlyList<T>.
Type Parameters
TType of element.
Remarks
If list implements INotifyCollectionChanged then returned IReadOnlyList<T> will also implements INotifyCollectionChanged.
Reverse<T>(List<T>)
Make given list as reversed IList<T>.
public static IList<T> Reverse<T>(this List<T> list)
Parameters
listList<T>The list to be reversed.
Returns
Type Parameters
TType of element.
Remarks
The method is available for target framework before .NET 9.
SelectRandomElement<T>(IList<T>)
Select an element from given IList<T> randomly.
public static T SelectRandomElement<T>(this IList<T> list)
Parameters
Returns
- T
Element selected from IList<T>.
Type Parameters
TType of element.
SelectRandomElement<T>(IReadOnlyList<T>)
Select an element from given IList<T> randomly.
public static T SelectRandomElement<T>(this IReadOnlyList<T> list)
Parameters
listIReadOnlyList<T>
Returns
- T
Element selected from IList<T>.
Type Parameters
TType of element.
Shuffle<T>(IList<T>)
Shuffle elements in given list.
public static void Shuffle<T>(this IList<T> list)
Parameters
Type Parameters
TType of list element.
Shuffle<T>(IList<T>, int, int)
Shuffle elements in given list.
public static void Shuffle<T>(this IList<T> list, int index, int count)
Parameters
listIList<T>indexintIndex of first element in list to shuffle.
countintNumber of elements to shuffle.
Type Parameters
TType of list element.
ToArray<T>(IList<T>, int, int)
Copy elements to array.
public static T[] ToArray<T>(this IList<T> list, int index, int count)
Parameters
listIList<T>indexintIndex of first element in list to copy.
countintNumber of elements to copy.
Returns
- T[]
Array of copied elements
Type Parameters
TType of list element.
ToArray<T>(IReadOnlyList<T>, int, int)
Copy elements to array.
public static T[] ToArray<T>(this IReadOnlyList<T> list, int index, int count)
Parameters
listIReadOnlyList<T>indexintIndex of first element in list to copy.
countintNumber of elements to copy.
Returns
- T[]
Array of copied elements
Type Parameters
TType of list element.
ToArray<T>(List<T>, int, int)
Copy elements to array.
public static T[] ToArray<T>(this List<T> list, int index, int count)
Parameters
listList<T>indexintIndex of first element in list to copy.
countintNumber of elements to copy.
Returns
- T[]
Array of copied elements
Type Parameters
TType of list element.
Remarks
The method is available for target framework before .NET 9.