Method ElementAtAsync
View SourceElementAtAsync<TSource>(IAsyncEnumerable<TSource>, Index, CancellationToken)
Returns the element at a specified index in a sequence.
Declaration
public static ValueTask<TSource> ElementAtAsync<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> | The element at the specified position in the |
Type Parameters
Name | Description |
---|---|
TSource | The type of the elements of |
Remarks
This method throws an exception if index
is out of range.
To instead return a default value when the specified index is out of range,
use the ElementAtOrDefaultAsync<TSource>(IAsyncEnumerable<TSource>, Index, CancellationToken) method.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|