Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


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.

C#
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);

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

ValueTask<TSource>

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.

Applies to

Termék Verziók
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided), 10
.NET Standard 2.0 (package-provided)