AsyncEnumerable.ElementAtAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
ElementAtAsync<TSource>(IAsyncEnumerable<TSource>, Index, CancellationToken) |
Returns the element at a specified index in a sequence. |
ElementAtAsync<TSource>(IAsyncEnumerable<TSource>, Int32, CancellationToken) |
Returns the element at a specified index in a sequence. |
ElementAtAsync<TSource>(IAsyncEnumerable<TSource>, Index, CancellationToken)
- Source:
- ElementAtAsync.cs
Returns the element at a specified index in a sequence.
public static System.Threading.Tasks.ValueTask<TSource> ElementAtAsync<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, Index index, System.Threading.CancellationToken cancellationToken = default);
static member ElementAtAsync : System.Collections.Generic.IAsyncEnumerable<'Source> * Index * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Source>
<Extension()>
Public Function ElementAtAsync(Of TSource) (source As IAsyncEnumerable(Of TSource), index As Index, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of TSource)
Type Parameters
- TSource
The type of the elements of source
.
Parameters
- source
- IAsyncEnumerable<TSource>
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 token to monitor for cancellation requests. The default value is None.
Returns
The element at the specified position in the source
sequence.
Exceptions
source
is null
.
index
is outside the bounds of the source sequence (via the returned task).
Remarks
If the type of source
implements IList<T>, that implementation is used to obtain the element at the specified index. Otherwise, this method obtains the specified element.
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 method.
Applies to
ElementAtAsync<TSource>(IAsyncEnumerable<TSource>, Int32, CancellationToken)
- Source:
- ElementAtAsync.cs
Returns the element at a specified index in a sequence.
public static System.Threading.Tasks.ValueTask<TSource> ElementAtAsync<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, int index, System.Threading.CancellationToken cancellationToken = default);
static member ElementAtAsync : System.Collections.Generic.IAsyncEnumerable<'Source> * int * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Source>
<Extension()>
Public Function ElementAtAsync(Of TSource) (source As IAsyncEnumerable(Of TSource), index As Integer, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of TSource)
Type Parameters
- TSource
The type of the elements of source.
Parameters
- source
- IAsyncEnumerable<TSource>
An IAsyncEnumerable<T> to return an element from.
- index
- Int32
The index of the element to retrieve, which is either from the beginning or the end of the sequence.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
The element at the specified position in the source sequence.
Exceptions
source
is null
.
index
is outside the bounds of the source sequence (via the returned task).