Legend

Class
Struct
Enum
Interface
Delegate
Constructor
Method
Property
Event
Field

Extension method: TResult MaxOrDefault<TSource, TResult>(this IEnumerable<TSource>, Func<TSource, TResult>, TResult)

Declaration

public static TResult MaxOrDefault<TSource, TResult>(
    this IEnumerable<TSource> source,
    Func<TSource, TResult> selector,
    TResult default = null
)

Summary

Invokes a selector on each element of a collection and returns the maximum resulting value, or a default value if the sequence is empty.

Generic type parameters

TSource The type of the elements of source.
TResult The type of the value returned by selector.

Parameters

this IEnumerable<TSource>source A sequence of values to determine the maximum value of.
Func<TSource, TResult>selector A transform function to apply to each element.
TResultdefault A default value to return in case the sequence is empty.

Returns

The maximum value in the sequence, or the specified default value if the sequence is empty.