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