IEnumerable<T>.ElementAtOrDefault Method

Overloads

ElementAtOrDefault(Integer)

Returns the element at a specified index in the sequence or a default value if the index is out of range.

ElementAtOrDefault(Integer, T)

Returns the element at a specified index in the sequence or the specified default value if the index is out of range.

ElementAtOrDefault(Integer)

Returns the element at a specified index in the sequence or a default value if the index is out of range.

Delphi
function ElementAtOrDefault(index: Integer): T

Parameters

index
Integer

The zero-based index of the element to retrieve.

Returns

T

Default(T) if the index is outside the bounds of the sequence; otherwise, the element at the specified position in the sequence.

ElementAtOrDefault(Integer, T)

Returns the element at a specified index in the sequence or the specified default value if the index is out of range.

Delphi
function ElementAtOrDefault(index: Integer; const defaultValue: T): T

Parameters

index
Integer

The zero-based index of the element to retrieve.

defaultValue
T

The value to return if the index is out of range.

Returns

T

defaultValue if the index is outside the bounds of the sequence; otherwise, the element at the specified position in the sequence.