AsyncEnumerable.ElementAtOrDefaultAsync Method (System.Linq) (original) (raw)

Definition

Namespace:

System.Linq

Assembly:

System.Linq.AsyncEnumerable.dll

Package:

System.Linq.AsyncEnumerable v10.0.0-preview.5.25277.114

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

ElementAtOrDefaultAsync(IAsyncEnumerable, Int32, CancellationToken)

Source:

ElementAtAsync.cs

Source:

ElementAtAsync.cs

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

public static System.Threading.Tasks.ValueTask<TSource?> ElementAtOrDefaultAsync<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, int index, System.Threading.CancellationToken cancellationToken = default);
static member ElementAtOrDefaultAsync : System.Collections.Generic.IAsyncEnumerable<'Source> * int * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Source>
<Extension()>
Public Function ElementAtOrDefaultAsync(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

index

Int32

The index of the element to retrieve, which is either from the beginning or the end of the sequence.

Returns

The default value of TSource if index is outside the bounds of the source sequence; otherwise, the element at the specified position in the source sequence.

Exceptions

Applies to

ElementAtOrDefaultAsync(IAsyncEnumerable, Index, CancellationToken)

Source:

ElementAtAsync.cs

Source:

ElementAtAsync.cs

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

public static System.Threading.Tasks.ValueTask<TSource?> ElementAtOrDefaultAsync<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, Index index, System.Threading.CancellationToken cancellationToken = default);
static member ElementAtOrDefaultAsync : System.Collections.Generic.IAsyncEnumerable<'Source> * Index * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Source>
<Extension()>
Public Function ElementAtOrDefaultAsync(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

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

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

Exceptions

Remarks

If the type of source implements IList, that implementation is used to obtain the element at the specified index. Otherwise, this method obtains the specified element.

The default value for reference and nullable types is null.

Applies to