Legend

Class
Struct
Enum
Interface
Delegate
Constructor
Method
Property
Event
Field

Static class: RT.Util.ExtensionMethods.CollectionExtensions

Summary

Provides extension methods on various collection types or interfaces in the System.Collections.Generic namespace such as Dictionary<TKey, TValue> and on arrays.

Static methods

void
AddRange<T>(this HashSet<T> set, IEnumerable<T> values)
Adds several values into a HashSet<T>.
void
BinarySearch<TK, TV>(this SortedList<TK, TV> list, TK key, out int index1, out int index2)
Performs a binary search for the specified key on a SortedList<T1, T2>. When no match exists, returns the nearest indices for interpolation/extrapolation purposes. (see also remarks)
bool
Contains<TKey, TValue>(this IDictionary<TKey, HashSet<TValue>> source, TKey key, TValue value)
Determines whether the current HashSet-in-a-Dictionary contains the specified key and value.
bool
ContainsKeys<TKey1, TKey2, TValue>(this IDictionary<TKey1, Dictionary<TKey2, TValue>> source, TKey1 key1, TKey2 key2)
Determines whether the current two-level dictionary contains the specified combination of keys.
IDictionary<TKey, TValue>
CopyMerge<TKey, TValue>(this IDictionary<TKey, TValue> first, IDictionary<TKey, TValue> second)
Creates a new dictionary containing the union of the key/value pairs contained in the specified dictionaries. Keys in second overwrite keys in first.
bool
DictionaryEqual<TK, TV>(this IDictionary<TK, TV> dictA, IDictionary<TK, TV> dictB)
Compares two dictionaries for equality, member-wise. Two dictionaries are equal if they contain all the same key-value pairs.
void
EnqueueRange<T>(this Queue<T> queue, IEnumerable<T> values)
Enqueues several values into a Queue<T>.
TValue
Get<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, TValue defaultVal)
Gets a value from a dictionary by key. If the key does not exist in the dictionary, the default value is returned instead.
TValue?
Get<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, TValue? defaultVal = null)
TValue
Get<TKey1, TKey2, TValue>(this IDictionary<TKey1, Dictionary<TKey2, TValue>> dict, TKey1 key1, TKey2 key2, TValue defaultVal)
Gets a value from a two-level dictionary by key. If the keys don’t exist in the dictionary, the default value is returned instead.
int
IndexOfSubarray<T>(this T[] sourceArray, T[] findWhat, IEqualityComparer<T> comparer = null)
Searches the current array for a specified subarray and returns the index of the first occurrence, or -1 if not found.
int
IndexOfSubarray<T>(this T[] sourceArray, T[] findWhat, int startIndex, int? sourceLength = null, IEqualityComparer<T> comparer = null)
T[]
Insert<T>(this T[] array, int startIndex, params T[] values)
Similar to string.Insert(int, string), but for arrays. Returns a new array with the values inserted starting from the specified startIndex. (see also remarks)
T[]
Insert<T>(this T[] array, int startIndex, T value)
Similar to string.Insert(int, string), but for arrays and for a single value. Returns a new array with the value inserted at the specified startIndex.
void
Pop<T>(this Stack<T> stack, int count)
Pops the specified number of elements from the stack. There must be at least that many items on the stack, otherwise an exception is thrown.
T[]
Remove<T>(this T[] array, int startIndex)
Similar to string.Remove(int), but for arrays. Returns a new array containing only the items before the specified startIndex. (see also remarks)
T[]
Remove<T>(this T[] array, int startIndex, int length)
Similar to string.Remove(int, int), but for arrays. Returns a new array containing everything except the length items starting from the specified startIndex. (see also remarks)
void
RemoveAll<TKey, TVal>(this IDictionary<TKey, TVal> dict, Func<KeyValuePair<TKey, TVal>, bool> predicate)
Removes all entries from a dictionary that satisfy a specified predicate.
void
RemoveAllByKey<TKey, TVal>(this IDictionary<TKey, TVal> dict, Func<TKey, bool> predicate)
Removes all entries from a dictionary whose keys satisfy a specified predicate.
void
RemoveAllByValue<TKey, TVal>(this IDictionary<TKey, TVal> dict, Func<TVal, bool> predicate)
Removes all entries from a dictionary whose values satisfy a specified predicate.
void
RemoveRange<T>(this List<T> list, IEnumerable<T> values)
Removes several values from a List<T>.
T[]
Replace<T>(this T[] array, int index, T element)
Returns a new array in which a single element has been replaced.
ListSelectIterator<TInput, TInput>
Reverse<TInput>(this IList<TInput> source)
Inverts the order of the elements in a sequence. (see also remarks)
T[]
ReverseInplace<T>(this T[] input)
Reverses an array in-place and returns the same array.
ListSelectIterator<TInput, TResult>
Select<TInput, TResult>(this IList<TInput> source, Func<TInput, TResult> selector)
Projects each element of a sequence into a new form. (see also remarks)
T[]
Subarray<T>(this T[] array, int startIndex)
Similar to string.Substring(int), but for arrays. Returns a new array containing all items from the specified startIndex onwards. (see also remarks)
T[]
Subarray<T>(this T[] array, int startIndex, int length)
Similar to string.Substring(int, int), but for arrays. Returns a new array containing length items from the specified startIndex onwards. (see also remarks)
bool
SubarrayEquals<T>(this T[] sourceArray, int sourceStartIndex, T[] otherArray, IEqualityComparer<T> comparer = null)
Determines whether a subarray within the current array is equal to the specified other array.
bool
SubarrayEquals<T>(this T[] sourceArray, int sourceStartIndex, T[] otherArray, int otherStartIndex, int length, IEqualityComparer<T> comparer = null)
Determines whether the two arrays contain the same content in the specified location.
Dictionary<TKey, TValue>
ToDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, IEqualityComparer<TKey> comparer = null, bool ignoreDuplicateKeys = false)
Converts an IEnumerable<KeyValuePair<TKey, TValue>> into a Dictionary<TKey, TValue>.
bool
TryGetValue<TKey1, TKey2, TValue>(this IDictionary<TKey1, Dictionary<TKey2, TValue>> source, TKey1 key1, TKey2 key2, out TValue value)
Gets the value associated with the specified combination of keys.