Enumerable.MaxBy Method (System.Linq) (original) (raw)
Source:
Source:
Source:
Source:
Returns the maximum 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 MaxBy(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, TKey> ^ keySelector, System::Collections::Generic::IComparer<TKey> ^ comparer);public static TSource? MaxBy<TSource,TKey>(this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,TKey> keySelector, System.Collections.Generic.IComparer<TKey>? comparer);static member MaxBy : seq<'Source> * Func<'Source, 'Key> * System.Collections.Generic.IComparer<'Key> -> 'Source<Extension()>
Public Function MaxBy(Of TSource, TKey) (source As IEnumerable(Of TSource), keySelector As Func(Of TSource, TKey), comparer As IComparer(Of TKey)) As TSourceType Parameters
TSource
The type of the elements of source.
TKey
The type of key to compare elements by.
Parameters
source
A sequence of values to determine the maximum value of.
keySelector
Func<TSource,TKey>
A function to extract the key for each element.
Returns
TSource
The value with the maximum key in the sequence.
Exceptions
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.