Returns the minimal element of the given sequence, based on
the given projection.
Declaration Syntax
C# | Visual Basic | Visual C++ |
public static TSource MinBy<TSource, TKey>( this IEnumerable<TSource> source, Func<TSource, TKey> selector )
<ExtensionAttribute> _ Public Shared Function MinBy(Of TSource, TKey) ( _ source As IEnumerable(Of TSource), _ selector As Func(Of TSource, TKey) _ ) As TSource
public: [ExtensionAttribute] generic<typename TSource, typename TKey> static TSource MinBy( IEnumerable<TSource>^ source, Func<TSource, TKey>^ selector )
Generic Template Parameters
- TSource
- Type of the source sequence
- TKey
- Type of the projected element
Parameters
- source (IEnumerable<(Of <(<'TSource>)>)>)
- Source sequence
- selector (Func<(Of <(<'TSource, TKey>)>)>)
- Selector to use to pick the results to compare
Return Value
The minimal element, according to the projection.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable<(Of <(<'TSource>)>)>. When you use instance method syntax to call this method, omit the first parameter.
Remarks
If more than one element has the minimal projected value, the first
one encountered will be returned. This overload uses the default comparer
for the projected type. This operator uses immediate execution, but
only buffers a single result (the current minimal element).
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | source or selector is null |
InvalidOperationException | source is empty |
Assembly: MoreLinq (Module: MoreLinq.dll) Version: 1.0.16006.0 (1.0.16006.1845)