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. |
Returns the last element of the sequence, or a default value if the sequence contains no elements.
function LastOrDefault: T
Returns
Default(T) if the sequence is empty; otherwise, the last
element in the sequence.
Returns the last element of the sequence, or the specified default value if the sequence contains no elements.
function LastOrDefault(const defaultValue: T): T
Parameters
- defaultValue
- T
The default value to return if the sequence is empty.
Returns
defaultValue if the sequence is empty; otherwise, the last
element in the sequence.
Returns the last element of the sequence that satisfies the specified condition or a default value if no such element is found.
function LastOrDefault(const predicate: Predicate<T>): T
Parameters
- predicate
- Predicate<T>
A function to test each element for a condition.
Returns
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 .
Returns the last element of the sequence that satisfies the specified condition or the specified default value if no such element is found.
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
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 .