AsyncEnumerable.MaxAsync<TSource> 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.
Returns the maximum value in a generic sequence.
public static System.Threading.Tasks.ValueTask<TSource?> MaxAsync<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, System.Collections.Generic.IComparer<TSource>? comparer = default, System.Threading.CancellationToken cancellationToken = default);
static member MaxAsync : System.Collections.Generic.IAsyncEnumerable<'Source> * System.Collections.Generic.IComparer<'Source> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Source>
<Extension()>
Public Function MaxAsync(Of TSource) (source As IAsyncEnumerable(Of TSource), Optional comparer As IComparer(Of TSource) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of TSource)
Type Parameters
- TSource
The type of the elements of source
.
Parameters
- source
- IAsyncEnumerable<TSource>
A sequence of values to determine the maximum value of.
- comparer
- IComparer<TSource>
The IComparer<T> to compare values.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
The maximum value in the sequence.
Exceptions
source
is null
.
No object in source
implements the IComparable or IComparable<T> interface (via the returned task).
Remarks
If type TSource
implements IComparable<T>, the MaxAsync<TSource>(IAsyncEnumerable<TSource>, IComparer<TSource>, CancellationToken) method uses that implementation to compare values. Otherwise, if type TSource
implements IComparable, that implementation is used to compare values.
If TSource
is a reference type and the source sequence is empty or contains only values that are null
, this method returns null
.