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

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

A sequence of values to determine the maximum value of.

Returns

The maximum value in the sequence.

Exceptions

Remarks

If type TSource implements IComparable, the MaxAsync(IAsyncEnumerable, IComparer, 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.

Applies to