MoreLinq
MaxBy<(Of <(<'TSource, TKey>)>)> Method (source, selector)
NamespacesMoreLinqMoreEnumerableMaxBy<(Of <<'(TSource, TKey>)>>)(IEnumerable<(Of <<'(TSource>)>>), Func<(Of <<'(TSource, TKey>)>>))
Returns the maximal element of the given sequence, based on the given projection.
Declaration Syntax
C#Visual BasicVisual C++
public static TSource MaxBy<TSource, TKey>(
	this IEnumerable<TSource> source,
	Func<TSource, TKey> selector
)
<ExtensionAttribute> _
Public Shared Function MaxBy(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 MaxBy(
	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 maximal 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 maximal 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 maximal element).
Exceptions
ExceptionCondition
ArgumentNullExceptionsource or selector is null
InvalidOperationExceptionsource is empty

Assembly: MoreLinq (Module: MoreLinq.dll) Version: 1.0.16006.0 (1.0.16006.1845)