Click or drag to resize

XEnumerableMinByTSource, TKey Method

Returns the element of the sequence that has the minimum value for the specified key.

Namespace:  Linq.Extras
Assembly:  Linq.Extras (in Linq.Extras.dll) Version: 5.0.0+96a4f4bfed64095342c5df107c1fe1fb95603ee5
Syntax
public static TSource MinBy<TSource, TKey>(
	this IEnumerable<TSource> source,
	Func<TSource, TKey> keySelector,
	IComparer<TKey>? keyComparer = null
)

Parameters

source
Type: System.Collections.GenericIEnumerableTSource
The sequence to return an element from.
keySelector
Type: SystemFuncTSource, TKey
A delegate that returns the key used to compare elements.
keyComparer (Optional)
Type: System.Collections.GenericIComparerTKey
A comparer to compare the keys.

Type Parameters

TSource
The type of the elements of source.
TKey
The type of the key used to compare elements.

Return Value

Type: TSource
The element of source that has the minimum value for the specified key.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableTSource. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Remarks
If TKey is a reference type or nullable value type, null keys are ignored, unless the sequence consists entirely of items with null keys (in which case the method will return null). If TKey is a reference type or nullable value type, and the sequence is empty, the method will return null. If TKey is a value type, and the sequence is empty, the method will throw an InvalidOperationException.
See Also