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
T
Type 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
list
IList<T>List to find element.
element
TElement to be found.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
T
Type 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
list
IList<T>List to find element.
element
TElement to be found.
comparer
IComparer<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
T
Type 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
list
IList<T>List to find element.
element
TElement to be found.
comparison
Comparison<T>Comparison function.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
T
Type 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
list
IReadOnlyList<T>List to find element.
element
TElement to be found.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
T
Type 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
list
IReadOnlyList<T>List to find element.
element
TElement to be found.
comparer
IComparer<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
T
Type 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
list
IReadOnlyList<T>List to find element.
element
TElement to be found.
comparison
Comparison<T>Comparison function.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
T
Type 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
list
IList<T>List to find element.
key
TKeyKey of element to be found.
keyGetter
Func<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
T
Type of element.
TKey
Type 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
list
IList<T>List to find element.
key
TKeyKey of element to be found.
keyGetter
Func<T, TKey>Method to get key from element.
comparison
Comparison<TKey>Comparison function.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
T
Type of element.
TKey
Type 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
list
IReadOnlyList<T>List to find element.
key
TKeyKey of element to be found.
keyGetter
Func<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
T
Type of element.
TKey
Type 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
list
IReadOnlyList<T>List to find element.
key
TKeyKey of element to be found.
keyGetter
Func<T, TKey>Method to get key from element.
comparison
Comparison<TKey>Comparison function.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
T
Type of element.
TKey
Type 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
list
List<T>List to find element.
key
TKeyKey of element to be found.
keyGetter
Func<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
T
Type of element.
TKey
Type 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
list
List<T>List to find element.
key
TKeyKey of element to be found.
keyGetter
Func<T, TKey>Method to get key from element.
comparison
Comparison<TKey>Comparison function.
Returns
- int
Index of found element, or bitwise complement of index of proper position to put element.
Type Parameters
T
Type of element.
TKey
Type of key of element.
Cast<TOut>(IList)
Case given list to generic typed list.
public static IList<TOut> Cast<TOut>(this IList list)
Parameters
list
IListList.
Returns
- IList<TOut>
Generic typed list.
Type Parameters
TOut
Type 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
list
IList<T>index
intIndex of first element in list to copy.
array
T[]Array to place copied elements.
arrayIndex
intIndex of first position in
array
to place copied elements.count
intNumber of elements to copy.
Type Parameters
T
Type 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
list
IReadOnlyList<T>index
intIndex of first element in list to copy.
array
T[]Array to place copied elements.
arrayIndex
intIndex of first position in
array
to place copied elements.count
intNumber of elements to copy.
Type Parameters
T
Type 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
list
List<T>The list.
index
intIndex of first element in list to copy.
array
T[]Array to place copied elements.
arrayIndex
intIndex of first position in
array
to place copied elements.count
intNumber of elements to copy.
Type Parameters
T
Type 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
list
IList<T>Source list.
start
intStart index of range.
count
intNumber of elements needed to be included.
Returns
- IList<T>
View of range of source list.
Type Parameters
T
Type 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
list
IReadOnlyList<T>Source list.
start
intStart index of range.
count
intNumber of elements needed to be included.
Returns
- IReadOnlyList<T>
View of range of source list.
Type Parameters
T
Type 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
list
List<T>Source list.
start
intStart index of range.
count
intNumber of elements needed to be included.
Returns
- IList<T>
View of range of source list.
Type Parameters
T
Type 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
list
List<T>List to check.
Returns
- bool
True if the list is empty.
Type Parameters
T
Type 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
list
List<T>List to check.
Returns
- bool
True if the list is not empty.
Type Parameters
T
Type 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
collection
List<T>List to check.
Returns
- bool
True if the list is null or empty.
Type Parameters
T
Type 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
T
Type 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
list
IList<T>comparer
IComparer<T>IComparer<T> to check order of elements.
Returns
Type Parameters
T
Type 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
list
IList<T>comparison
Comparison<T>Comparison method to check order of elements.
Returns
Type Parameters
T
Type 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
list
IReadOnlyList<T>
Returns
- bool
True if elements in IReadOnlyList<T> are sorted.
Type Parameters
T
Type 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
list
IReadOnlyList<T>comparer
IComparer<T>IComparer<T> to check order of elements.
Returns
- bool
True if elements in IReadOnlyList<T> are sorted.
Type Parameters
T
Type 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
list
IReadOnlyList<T>comparison
Comparison<T>Comparison method to check order of elements.
Returns
- bool
True if elements in IReadOnlyList<T> are sorted.
Type Parameters
T
Type 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
T
Type 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
list
List<T>List.
comparer
IComparer<T>IComparer<T> to check order of elements.
Returns
- bool
True if elements in the list are sorted.
Type Parameters
T
Type 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
list
List<T>comparison
Comparison<T>Comparison method to check order of elements.
Returns
Type Parameters
T
Type 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
T
Type 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
T
Type 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
list
IReadOnlyList<T>IReadOnlyList<T> to be reversed.
Returns
- IReadOnlyList<T>
Reversed IReadOnlyList<T>.
Type Parameters
T
Type 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
list
List<T>The list to be reversed.
Returns
Type Parameters
T
Type 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
T
Type of element.
SelectRandomElement<T>(IReadOnlyList<T>)
Select an element from given IList<T> randomly.
public static T SelectRandomElement<T>(this IReadOnlyList<T> list)
Parameters
list
IReadOnlyList<T>
Returns
- T
Element selected from IList<T>.
Type Parameters
T
Type of element.
Shuffle<T>(IList<T>)
Shuffle elements in given list.
public static void Shuffle<T>(this IList<T> list)
Parameters
Type Parameters
T
Type 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
list
IList<T>index
intIndex of first element in list to shuffle.
count
intNumber of elements to shuffle.
Type Parameters
T
Type 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
list
IList<T>index
intIndex of first element in list to copy.
count
intNumber of elements to copy.
Returns
- T[]
Array of copied elements
Type Parameters
T
Type 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
list
IReadOnlyList<T>index
intIndex of first element in list to copy.
count
intNumber of elements to copy.
Returns
- T[]
Array of copied elements
Type Parameters
T
Type 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
list
List<T>index
intIndex of first element in list to copy.
count
intNumber of elements to copy.
Returns
- T[]
Array of copied elements
Type Parameters
T
Type of list element.
Remarks
The method is available for target framework before .NET 9.