Class CollectionUtils
Some helpful extensions for standard collections
Inheritance
System.Object
CollectionUtils
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: NFX
Assembly: NFX.dll
Syntax
public static class CollectionUtils
Methods
AddRange<TKey, TValue>(IDictionary<TKey, TValue>, IEnumerable<KeyValuePair<TKey, TValue>>)
Add all values from range sequence to src IDictionary. Source is actually modified.
Declaration
public static IDictionary<TKey, TValue> AddRange<TKey, TValue>(this IDictionary<TKey, TValue> src, IEnumerable<KeyValuePair<TKey, TValue>> range)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IDictionary<TKey, TValue> |
src |
Source IDictionary (where to add range)
|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> |
range |
Sequence that should be added to source IDictionary
|
Returns
Type |
Description |
System.Collections.Generic.IDictionary<TKey, TValue> |
Source with added elements from range (to have ability to chain operations)
|
Type Parameters
Name |
Description |
TKey |
Type of key
|
TValue |
Type of value
|
AppendToNew<T>(T[], T[])
Returns a new array that contains source elements with additional elements appended at the end
Declaration
public static T[] AppendToNew<T>(this T[] source, params T[] elements)
Parameters
Type |
Name |
Description |
T[] |
source |
|
T[] |
elements |
|
Returns
Type Parameters
Distinct<TResult, TKey>(IEnumerable<TResult>, Func<TResult, TKey>)
Declaration
public static IEnumerable<TResult> Distinct<TResult, TKey>(this IEnumerable<TResult> source, Func<TResult, TKey> selector)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TResult> |
source |
|
System.Func<TResult, TKey> |
selector |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<TResult> |
|
Type Parameters
Name |
Description |
TResult |
|
TKey |
|
FirstMax<TResult, TComparand>(IEnumerable<TResult>, Func<TResult, TComparand>)
Declaration
public static TResult FirstMax<TResult, TComparand>(this IEnumerable<TResult> source, Func<TResult, TComparand> selector)where TComparand : IComparable
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TResult> |
source |
|
System.Func<TResult, TComparand> |
selector |
|
Returns
Type Parameters
Name |
Description |
TResult |
|
TComparand |
|
FirstMax<TResult, TComparand>(IEnumerable<TResult>, Func<TResult, TComparand>, out TComparand)
Declaration
public static TResult FirstMax<TResult, TComparand>(this IEnumerable<TResult> source, Func<TResult, TComparand> selector, out TComparand maxComparand)where TComparand : IComparable
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TResult> |
source |
|
System.Func<TResult, TComparand> |
selector |
|
TComparand |
maxComparand |
|
Returns
Type Parameters
Name |
Description |
TResult |
|
TComparand |
|
FirstMin<TResult, TComparand>(IEnumerable<TResult>, Func<TResult, TComparand>)
Declaration
public static TResult FirstMin<TResult, TComparand>(this IEnumerable<TResult> source, Func<TResult, TComparand> selector)where TComparand : IComparable
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TResult> |
source |
|
System.Func<TResult, TComparand> |
selector |
|
Returns
Type Parameters
Name |
Description |
TResult |
|
TComparand |
|
FirstMin<TResult, TComparand>(IEnumerable<TResult>, Func<TResult, TComparand>, out TComparand)
Declaration
public static TResult FirstMin<TResult, TComparand>(this IEnumerable<TResult> source, Func<TResult, TComparand> selector, out TComparand minComparand)where TComparand : IComparable
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TResult> |
source |
|
System.Func<TResult, TComparand> |
selector |
|
TComparand |
minComparand |
|
Returns
Type Parameters
Name |
Description |
TResult |
|
TComparand |
|
FirstOrAnyOrDefault<TResult>(IEnumerable<TResult>, Func<TResult, Boolean>)
Tries to find the first element that matches the predicate and returns it,
otherwise returns the first element found or default (i.e. null)
Declaration
public static TResult FirstOrAnyOrDefault<TResult>(this IEnumerable<TResult> source, Func<TResult, bool> predicate)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TResult> |
source |
|
System.Func<TResult, System.Boolean> |
predicate |
|
Returns
Type Parameters
ForEach<T>(IEnumerable<T>, Action<T, Int32>)
Runs some method over each element of src sequence
Declaration
public static IEnumerable<T> ForEach<T>(this IEnumerable<T> src, Action<T, int> action)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
src |
Source sequence
|
System.Action<T, System.Int32> |
action |
Method to call on each element and its sequence number
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
Source sequence (to have ability to chain similar calls)
|
Type Parameters
Name |
Description |
T |
Sequence item type
|
ForEach<T>(IEnumerable<T>, Action<T>)
Runs some method over each element of src sequence
Declaration
public static IEnumerable<T> ForEach<T>(this IEnumerable<T> src, Action<T> action)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
src |
Source sequence
|
System.Action<T> |
action |
Method to run over each element
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
Source sequence (to have ability to chain similar calls)
|
Type Parameters
Name |
Description |
T |
Sequence item type
|
SkipLast<T>(IEnumerable<T>)
Takes all elements except for last element from the given source
Declaration
public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
source |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters
SkipLast<T>(IEnumerable<T>, Int32)
Takes all but last N elements from the source
Declaration
public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source, int n)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
source |
|
System.Int32 |
n |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Type Parameters