Class ListExtensions
- Namespace
- SunamoExtensions
- Assembly
- SunamoExtensions.dll
Extension methods for List type
public static class ListExtensions
- Inheritance
-
ListExtensions
- Inherited Members
Methods
AddOrSet<T>(IList<T>, int, T)
Adds or sets an item at the specified index (sets if index exists, adds if not)
public static List<T> AddOrSet<T>(this IList<T> list, int index, T item)
Parameters
Returns
- List<T>
Modified list
Type Parameters
TType of elements in the list
AddRangeIfNotContain<T>(IList<T>, List<T>)
Adds multiple items to the list only if they don't already exist
public static void AddRangeIfNotContain<T>(this IList<T> list, List<T> itemsToAdd)
Parameters
Type Parameters
TType of elements in the list
Insert<T>(IList<T>, int, T)
Inserts an item at the specified index
public static List<T> Insert<T>(this IList<T> list, int index, T item)
Parameters
Returns
- List<T>
Modified list
Type Parameters
TType of elements in the list
Leading(List<string>, string)
Inserts an item at the beginning of the list NOTE: Leading items should be always the last in code, Add items should be first in code
public static List<string> Leading(this List<string> list, string item)
Parameters
Returns
LeadingRange(List<string>, IList<string>)
Inserts items at the beginning of the list (direct edit)
public static List<string> LeadingRange(this List<string> list, IList<string> items)
Parameters
Returns
NthOrderStatistic<T>(IList<T>, int, Random?)
Returns Nth smallest element from the list. Here n starts from 0 so that n=0 returns minimum, n=1 returns 2nd smallest element etc. Note: specified list would be mutated in the process. Reference: Introduction to Algorithms 3rd Edition, Corman et al, pp 216
public static T NthOrderStatistic<T>(this IList<T> list, int n, Random? rnd = null) where T : IComparable<T>
Parameters
listIList<T>List to find Nth order statistic in
nintOrder statistic to find (0-based, 0 = minimum)
rndRandomOptional random number generator
Returns
- T
Nth smallest element
Type Parameters
TType of elements that implements IComparable
Partition<T>(IList<T>, int, int, Random?)
Partitions the given list around a pivot element such that all elements on left of pivot are <= pivot and the ones at the right are > pivot. This method can be used for sorting, N-order statistics such as median finding algorithms. Pivot is selected randomly if random number generator is supplied else its selected as last element in the list. Reference: Introduction to Algorithms 3rd Edition, Corman et al, pp 171
public static int Partition<T>(this IList<T> list, int start, int end, Random? rnd = null) where T : IComparable<T>
Parameters
listIList<T>List to partition (must be List due to working with indexes)
startintStart index
endintEnd index
rndRandomOptional random number generator for pivot selection
Returns
- int
Index of the pivot element after partitioning
Type Parameters
TType of elements that implements IComparable
RemoveMany(IList<string>, List<string>)
Removes multiple string items from the list
public static void RemoveMany(this IList<string> list, List<string> itemsToRemove)
Parameters
RemoveMany<T>(IList<T>, List<T>)
Removes multiple items from the list
public static void RemoveMany<T>(this IList<T> list, List<T> itemsToRemove)
Parameters
Type Parameters
TType of elements in the list