Method MinBy
- Namespace
- Gamelogic.Extensions.Algorithms
- Assembly
- Gamelogic.Extensions.dll
MinBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>)
Finds the minimum element in the source as scored by its projection.
public static TSource MinBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> selector)
Parameters
sourceIEnumerable<TSource>The source to find the minimum in.
selectorFunc<TSource, TKey>A function to extract a comparable key from each element.
Returns
- TSource
The element with the smallest key.
Type Parameters
TSourceThe type of elements in the source.
TKeyThe type of the key used to compare elements.
Exceptions
- InvalidOperationException
The sequence is empty.
MinBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>, IComparer<TKey>)
Finds the minimum element in the source as scored by the given function applied to a projection on the elements.
public static TSource MinBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> selector, IComparer<TKey> comparer)
Parameters
sourceIEnumerable<TSource>The source to find the minimum in.
selectorFunc<TSource, TKey>A function to extract a comparable key from each element.
comparerIComparer<TKey>The comparer to use when comparing keys.
Returns
- TSource
The element with the smallest key.
Type Parameters
TSourceThe type of elements in the source.
TKeyThe type of the key used to compare elements.
Exceptions
- InvalidOperationException
The sequence is empty.