IEnumerable<T>.Single Method

Overloads

Single

Returns the only element of the sequence, and raises an exception if there is not exactly one element in the sequence.

Single(Predicate<T>)

Returns the only element of the sequence that satisfies a specified condition, and raises an exception if more than one such element exists.

Single

Returns the only element of the sequence, and raises an exception if there is not exactly one element in the sequence.

Delphi
function Single: T

Returns

T

The single element of the sequence.

Exceptions

The input sequence contains more than one element.

-or-

The input sequence is empty.

Single(Predicate<T>)

Returns the only element of the sequence that satisfies a specified condition, and raises an exception if more than one such element exists.

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

Parameters

predicate
Predicate<T>

A function to test an element for a condition.

Returns

T

The single element of the sequence that satisfies a condition.

Exceptions

predicate is nil .

No element satisfies the condition in predicate .

-or-

More than one element satisfies the condition in predicate .

-or-

The sequence is empty.