IEnumerable<T>.LastOrDefault Method

Overloads

LastOrDefault

Returns the last element of the sequence, or a default value if the sequence contains no elements.

LastOrDefault(T)

Returns the last element of the sequence, or the specified default value if the sequence contains no elements.

LastOrDefault(Predicate<T>)

Returns the last element of the sequence that satisfies the specified condition or a default value if no such element is found.

LastOrDefault(Predicate<T>, T)

Returns the last element of the sequence that satisfies the specified condition or the specified default value if no such element is found.

LastOrDefault

Returns the last element of the sequence, or a default value if the sequence contains no elements.

Delphi
function LastOrDefault: T

Returns

T

Default(T) if the sequence is empty; otherwise, the last element in the sequence.

LastOrDefault(T)

Returns the last element of the sequence, or the specified default value if the sequence contains no elements.

Delphi
function LastOrDefault(const defaultValue: T): T

Parameters

defaultValue
T

The default value to return if the sequence is empty.

Returns

T

defaultValue if the sequence is empty; otherwise, the last element in the sequence.

LastOrDefault(Predicate<T>)

Returns the last element of the sequence that satisfies the specified condition or a default value if no such element is found.

Delphi
function LastOrDefault(const predicate: Predicate<T>): T

Parameters

predicate
Predicate<T>

A function to test each element for a condition.

Returns

T

default(T) if the sequence is empty or if no elements pass the test in the predicate function; otherwise, the last element that passes the test in the predicate function.

Exceptions

predicate is nil .

LastOrDefault(Predicate<T>, T)

Returns the last element of the sequence that satisfies the specified condition or the specified default value if no such element is found.

Delphi
function LastOrDefault(const predicate: Predicate<T>; const defaultValue: T): T

Parameters

predicate
Predicate<T>

A function to test each element for a condition.

defaultValue
T

The default value to return if the sequence is empty or no element passes the condition.

Returns

T

default(TSource) if the sequence is empty or if no element passes the test specified by predicate ; otherwise, the first element in the sequence that passes the test specified by predicate .

Exceptions

predicate is nil .