Enumerable.MaxBy 方法

定義

多載

MaxBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

根據指定的索引鍵選取器函式,傳回泛型序列中的最大值。

MaxBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IComparer<TKey>)

根據指定的索引鍵選取器函式和索引鍵比較子,傳回泛型序列中的最大值。

MaxBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

根據指定的索引鍵選取器函式,傳回泛型序列中的最大值。

public:
generic <typename TSource, typename TKey>
[System::Runtime::CompilerServices::Extension]
 static TSource MaxBy(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, TKey> ^ keySelector);
public static TSource? MaxBy<TSource,TKey> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,TKey> keySelector);
static member MaxBy : seq<'Source> * Func<'Source, 'Key> -> 'Source
<Extension()>
Public Function MaxBy(Of TSource, TKey) (source As IEnumerable(Of TSource), keySelector As Func(Of TSource, TKey)) As TSource

類型參數

TSource

source 項目的類型。

TKey

要比較項目依據的索引鍵類型。

參數

source
IEnumerable<TSource>

要判斷最大值的值序列。

keySelector
Func<TSource,TKey>

用來擷取各項目之索引鍵的函式。

傳回

TSource

序列中索引鍵上限的值。

例外狀況

sourcenull

從中 source 擷取的索引鍵不會實作 IComparableIComparable<T> 介面。

TSource 是基本類型,而來源序列是空的。

備註

如果來源序列是空的,而且 TSource 是可為 Null 的類型,這個方法會傳 null回 。 如果來源序列是空的,而且 TSource 是不可為 Null 的結構,例如基本類型, InvalidOperationException 則會擲回 。

如果來源序列只包含的值為 null

適用於

MaxBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IComparer<TKey>)

根據指定的索引鍵選取器函式和索引鍵比較子,傳回泛型序列中的最大值。

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 TSource

類型參數

TSource

source 項目的類型。

TKey

要比較項目依據的索引鍵類型。

參數

source
IEnumerable<TSource>

要判斷最大值的值序列。

keySelector
Func<TSource,TKey>

用來擷取各項目之索引鍵的函式。

comparer
IComparer<TKey>

IComparer<T>要比較索引鍵的 。

傳回

TSource

序列中索引鍵上限的值。

例外狀況

sourcenull

從中 source 擷取的索引鍵不會實作 IComparableIComparable<T> 介面。

TSource 是基本類型,而來源序列是空的。

備註

如果來源序列是空的,而且 TSource 是可為 Null 的類型,這個方法會傳 null回 。 如果來源序列是空的,而且 TSource 是不可為 Null 的結構,例如基本類型, InvalidOperationException 則會擲回 。

如果來源序列只包含的值為 null

適用於