IEnumerable<T>.SingleOrDefault Method
Overloads
| SingleOrDefault |
Returns the only element of the sequence, or a default value if the sequence is empty; this method raises an exception if there is more than one element in the sequence. |
| SingleOrDefault(T) |
Returns the only element of the sequence, or a specified default value if the sequence is empty; this method raises an exception if there is more than one element in the sequence. |
| SingleOrDefault(Predicate<T>) |
Returns the only element of the sequence that satisfies a specified condition or a default value if no such element exists; this method raises an exception if more than one element satisfies the condition. |
| SingleOrDefault(Predicate<T>, T) |
Returns the only element of the sequence that satisfies a specified condition, or a specified default value if no such element exists; this method raises an exception if more than one element satisfies the condition. |
Returns the only element of the sequence, or a default value if the sequence is empty; this method raises an exception if there is more than one element in the sequence.
function SingleOrDefault: T
Returns
The single element of the input sequence, or Default(T) if the
sequence contains no elements.
Exceptions
The input sequence contains more than one element.
Returns the only element of the sequence, or a specified default value if the sequence is empty; this method raises an exception if there is more than one element in the sequence.
function SingleOrDefault(const defaultValue: T): T
Parameters
- defaultValue
- T
The default value to return if the sequence is empty.
Returns
The single element of the input sequence, or defaultValue if
the sequence contains no elements.
Exceptions
The input sequence contains more than one element.
Returns the only element of the sequence that satisfies a specified condition or a default value if no such element exists; this method raises an exception if more than one element satisfies the condition.
function SingleOrDefault(const predicate: Predicate<T>): T
Parameters
- predicate
- Predicate<T>
A function to test an element for a condition.
Returns
The single element of the input sequence that satisfies the
condition, or Default(T) if no such element is found.
Exceptions
predicate is nil .
More than one element satisfies the condition in predicate .
Returns the only element of the sequence that satisfies a specified condition, or a specified default value if no such element exists; this method raises an exception if more than one element satisfies the condition.
function SingleOrDefault(const predicate: Predicate<T>; const defaultValue: T): T
Parameters
- predicate
- Predicate<T>
A function to test an element for a condition.
- defaultValue
- T
The default value to return if the sequence is empty.
Returns
The single element of the input sequence that satisfies the
condition, or defaultValue if no such element is found.
Exceptions
predicate is nil .
More than one element satisfies the condition in predicate .