Enumerable.MinBy Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
MinBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>) |
Returns the minimum value in a generic sequence according to a specified key selector function. |
MinBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IComparer<TKey>) |
Returns the minimum value in a generic sequence according to a specified key selector function and key comparer. |
MinBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Returns the minimum value in a generic sequence according to a specified key selector function.
public:
generic <typename TSource, typename TKey>
[System::Runtime::CompilerServices::Extension]
static TSource MinBy(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, TKey> ^ keySelector);
public static TSource? MinBy<TSource,TKey> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,TKey> keySelector);
static member MinBy : seq<'Source> * Func<'Source, 'Key> -> 'Source
<Extension()>
Public Function MinBy(Of TSource, TKey) (source As IEnumerable(Of TSource), keySelector As Func(Of TSource, TKey)) As TSource
Type Parameters
- TSource
The type of the elements of source
.
- TKey
The type of key to compare elements by.
Parameters
- source
- IEnumerable<TSource>
A sequence of values to determine the minimum value of.
- keySelector
- Func<TSource,TKey>
A function to extract the key for each element.
Returns
The value with the minimum key in the sequence.
Exceptions
source
is null
.
No key extracted from source
implements the IComparable or IComparable<T> interface.
TSource
is a primitive type and the source sequence is empty.
Remarks
If the source sequence is empty, two possible outcomes are possible depending on the source type. If TSource
is a nullable type, this method returns null
. If TSource
is a non-nullable struct, such as a primitive type, an InvalidOperationException is thrown.
If the source sequence contains only values that are null
, this method returns null
.
Applies to
MinBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IComparer<TKey>)
- Source:
- Min.cs
- Source:
- Min.cs
- Source:
- Min.cs
Returns the minimum value in a generic sequence according to a specified key selector function and key comparer.
public:
generic <typename TSource, typename TKey>
[System::Runtime::CompilerServices::Extension]
static TSource MinBy(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, TKey> ^ keySelector, System::Collections::Generic::IComparer<TKey> ^ comparer);
public static TSource? MinBy<TSource,TKey> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,TKey> keySelector, System.Collections.Generic.IComparer<TKey>? comparer);
static member MinBy : seq<'Source> * Func<'Source, 'Key> * System.Collections.Generic.IComparer<'Key> -> 'Source
<Extension()>
Public Function MinBy(Of TSource, TKey) (source As IEnumerable(Of TSource), keySelector As Func(Of TSource, TKey), comparer As IComparer(Of TKey)) As TSource
Type Parameters
- TSource
The type of the elements of source
.
- TKey
The type of key to compare elements by.
Parameters
- source
- IEnumerable<TSource>
A sequence of values to determine the minimum value of.
- keySelector
- Func<TSource,TKey>
A function to extract the key for each element.
- comparer
- IComparer<TKey>
The IComparer<T> to compare keys.
Returns
The value with the minimum key in the sequence.
Exceptions
source
is null
.
No key extracted from source
implements the IComparable or IComparable<T> interface.
TSource
is a primitive type and the source sequence is empty.
Remarks
If the source sequence is empty, two possible outcomes are possible depending on the source type. If TSource
is a nullable type, this method returns null
. If TSource
is a non-nullable struct, such as a primitive type, an InvalidOperationException is thrown.
If the source sequence contains only values that are null
, this method returns null
.