Method ElementAtOrDefaultAsync
View SourceElementAtOrDefaultAsync<TSource>(IAsyncEnumerable<TSource>, Index, CancellationToken)
Returns the element at a specified index in a sequence or a default value if the index is out of range.
Declaration
public static ValueTask<TSource?> ElementAtOrDefaultAsync<TSource>(this IAsyncEnumerable<TSource> source, Index index, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<TSource> | source | An IAsyncEnumerable<T> to return an element from. |
Index | index | The index of the element to retrieve, which is either from the start or the end. |
CancellationToken | cancellationToken | The optional cancellation token to be used for cancelling the sequence at any time. |
Returns
Type | Description |
---|---|
ValueTask<TSource> | default if |
Type Parameters
Name | Description |
---|---|
TSource | The type of the elements of |
Remarks
The default value for reference and nullable types is null.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|