AsyncEnumerable.LastAsync 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
LastAsync<TSource>(IAsyncEnumerable<TSource>, CancellationToken) |
Returns the last element of a sequence. |
LastAsync<TSource>(IAsyncEnumerable<TSource>, Func<TSource,Boolean>, CancellationToken) |
Returns the last element of a sequence that satisfies a specified condition. |
LastAsync<TSource>(IAsyncEnumerable<TSource>, Func<TSource,CancellationToken,ValueTask<Boolean>>, CancellationToken) |
Returns the last element of a sequence that satisfies a specified condition. |
LastAsync<TSource>(IAsyncEnumerable<TSource>, CancellationToken)
- Source:
- LastAsync.cs
Returns the last element of a sequence.
public static System.Threading.Tasks.ValueTask<TSource> LastAsync<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, System.Threading.CancellationToken cancellationToken = default);
static member LastAsync : System.Collections.Generic.IAsyncEnumerable<'Source> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Source>
<Extension()>
Public Function LastAsync(Of TSource) (source As IAsyncEnumerable(Of TSource), 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 the last element of.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
The value at the last position in the source sequence.
Exceptions
source
is null
.
The source sequence is empty (via the returned task).
Applies to
LastAsync<TSource>(IAsyncEnumerable<TSource>, Func<TSource,Boolean>, CancellationToken)
- Source:
- LastAsync.cs
Returns the last element of a sequence that satisfies a specified condition.
public static System.Threading.Tasks.ValueTask<TSource> LastAsync<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, Func<TSource,bool> predicate, System.Threading.CancellationToken cancellationToken = default);
static member LastAsync : System.Collections.Generic.IAsyncEnumerable<'Source> * Func<'Source, bool> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Source>
<Extension()>
Public Function LastAsync(Of TSource) (source As IAsyncEnumerable(Of TSource), predicate As Func(Of TSource, Boolean), 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.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
The last element in the sequence that passes the test in the specified predicate function.
Exceptions
predicate
is null
.
The source sequence is empty, or no element in the sequence satisfies the condition in predicate (via the returned task).
Applies to
LastAsync<TSource>(IAsyncEnumerable<TSource>, Func<TSource,CancellationToken,ValueTask<Boolean>>, CancellationToken)
- Source:
- LastAsync.cs
Returns the last element of a sequence that satisfies a specified condition.
public static System.Threading.Tasks.ValueTask<TSource> LastAsync<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, Func<TSource,System.Threading.CancellationToken,System.Threading.Tasks.ValueTask<bool>> predicate, System.Threading.CancellationToken cancellationToken = default);
static member LastAsync : System.Collections.Generic.IAsyncEnumerable<'Source> * Func<'Source, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<bool>> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Source>
<Extension()>
Public Function LastAsync(Of TSource) (source As IAsyncEnumerable(Of TSource), predicate As Func(Of TSource, CancellationToken, ValueTask(Of Boolean)), 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.
- predicate
- Func<TSource,CancellationToken,ValueTask<Boolean>>
A function to test each element for a condition.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
The last element in the sequence that passes the test in the specified predicate function.
Exceptions
predicate
is null
.
The source sequence is empty, or no element in the sequence satisfies the condition in predicate (via the returned task).