AsyncEnumerable.AverageAsync 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

AverageAsync(IAsyncEnumerable<Nullable<Int64>>, CancellationToken)

Computes the average of a sequence of nullable values.

AverageAsync(IAsyncEnumerable<Single>, CancellationToken)

Computes the average of a sequence of values.

AverageAsync(IAsyncEnumerable<Nullable<Single>>, CancellationToken)

Computes the average of a sequence of nullable values.

AverageAsync(IAsyncEnumerable<Nullable<Double>>, CancellationToken)

Computes the average of a sequence of nullable values.

AverageAsync(IAsyncEnumerable<Nullable<Int32>>, CancellationToken)

Computes the average of a sequence of nullable values.

AverageAsync(IAsyncEnumerable<Int64>, CancellationToken)

Computes the average of a sequence of values.

AverageAsync(IAsyncEnumerable<Nullable<Decimal>>, CancellationToken)

Computes the average of a sequence of nullable values.

AverageAsync(IAsyncEnumerable<Int32>, CancellationToken)

Computes the average of a sequence of values.

AverageAsync(IAsyncEnumerable<Double>, CancellationToken)

Computes the average of a sequence of values.

AverageAsync(IAsyncEnumerable<Decimal>, CancellationToken)

Computes the average of a sequence of values.

AverageAsync(IAsyncEnumerable<Nullable<Int64>>, CancellationToken)

Source:
AverageAsync.cs

Computes the average of a sequence of nullable values.

public static System.Threading.Tasks.ValueTask<double?> AverageAsync(this System.Collections.Generic.IAsyncEnumerable<long?> source, System.Threading.CancellationToken cancellationToken = default);

Parameters

source
IAsyncEnumerable<Nullable<Int64>>

A sequence of nullable values to calculate the average of.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

The average of the sequence of values, or null if the source sequence is empty or contains only values that are null.

Exceptions

source is null.

The sum of the elements in the sequence is larger than MaxValue (via the returned task).

source contains no elements (via the returned task).

Applies to

.NET 10 and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided), 10
.NET Standard 2.0 (package-provided)

AverageAsync(IAsyncEnumerable<Single>, CancellationToken)

Source:
AverageAsync.cs

Computes the average of a sequence of values.

public static System.Threading.Tasks.ValueTask<float> AverageAsync(this System.Collections.Generic.IAsyncEnumerable<float> source, System.Threading.CancellationToken cancellationToken = default);

Parameters

source
IAsyncEnumerable<Single>

A sequence of values to calculate the average of.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

The average of the sequence of values.

Exceptions

source is null.

source contains no elements (via the returned task).

Applies to

.NET 10 and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided), 10
.NET Standard 2.0 (package-provided)

AverageAsync(IAsyncEnumerable<Nullable<Single>>, CancellationToken)

Source:
AverageAsync.cs

Computes the average of a sequence of nullable values.

public static System.Threading.Tasks.ValueTask<float?> AverageAsync(this System.Collections.Generic.IAsyncEnumerable<float?> source, System.Threading.CancellationToken cancellationToken = default);

Parameters

source
IAsyncEnumerable<Nullable<Single>>

A sequence of nullable values to calculate the average of.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

The average of the sequence of values, or null if the source sequence is empty or contains only values that are null.

Exceptions

source is null.

source contains no elements (via the returned task).

Applies to

.NET 10 and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided), 10
.NET Standard 2.0 (package-provided)

AverageAsync(IAsyncEnumerable<Nullable<Double>>, CancellationToken)

Source:
AverageAsync.cs

Computes the average of a sequence of nullable values.

public static System.Threading.Tasks.ValueTask<double?> AverageAsync(this System.Collections.Generic.IAsyncEnumerable<double?> source, System.Threading.CancellationToken cancellationToken = default);

Parameters

source
IAsyncEnumerable<Nullable<Double>>

A sequence of nullable values to calculate the average of.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

The average of the sequence of values, or null if the source sequence is empty or contains only values that are null.

Exceptions

source is null.

source contains no elements (via the returned task).

Applies to

.NET 10 and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided), 10
.NET Standard 2.0 (package-provided)

AverageAsync(IAsyncEnumerable<Nullable<Int32>>, CancellationToken)

Source:
AverageAsync.cs

Computes the average of a sequence of nullable values.

public static System.Threading.Tasks.ValueTask<double?> AverageAsync(this System.Collections.Generic.IAsyncEnumerable<int?> source, System.Threading.CancellationToken cancellationToken = default);

Parameters

source
IAsyncEnumerable<Nullable<Int32>>

A sequence of nullable values to calculate the average of.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

The average of the sequence of values, or null if the source sequence is empty or contains only values that are null.

Exceptions

source is null.

The sum of the elements in the sequence is larger than MaxValue (via the returned task).

source contains no elements (via the returned task).

Applies to

.NET 10 and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided), 10
.NET Standard 2.0 (package-provided)

AverageAsync(IAsyncEnumerable<Int64>, CancellationToken)

Source:
AverageAsync.cs

Computes the average of a sequence of values.

public static System.Threading.Tasks.ValueTask<double> AverageAsync(this System.Collections.Generic.IAsyncEnumerable<long> source, System.Threading.CancellationToken cancellationToken = default);

Parameters

source
IAsyncEnumerable<Int64>

A sequence of values to calculate the average of.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

The average of the sequence of values.

Exceptions

source is null.

The sum of the elements in the sequence is larger than MaxValue (via the returned task).

source contains no elements (via the returned task).

Applies to

.NET 10 and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided), 10
.NET Standard 2.0 (package-provided)

AverageAsync(IAsyncEnumerable<Nullable<Decimal>>, CancellationToken)

Source:
AverageAsync.cs

Computes the average of a sequence of nullable values.

public static System.Threading.Tasks.ValueTask<decimal?> AverageAsync(this System.Collections.Generic.IAsyncEnumerable<decimal?> source, System.Threading.CancellationToken cancellationToken = default);

Parameters

source
IAsyncEnumerable<Nullable<Decimal>>

A sequence of nullable values to calculate the average of.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

The average of the sequence of values, or null if the source sequence is empty or contains only values that are null.

Exceptions

source is null.

source contains no elements (via the returned task).

Applies to

.NET 10 and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided), 10
.NET Standard 2.0 (package-provided)

AverageAsync(IAsyncEnumerable<Int32>, CancellationToken)

Source:
AverageAsync.cs

Computes the average of a sequence of values.

public static System.Threading.Tasks.ValueTask<double> AverageAsync(this System.Collections.Generic.IAsyncEnumerable<int> source, System.Threading.CancellationToken cancellationToken = default);

Parameters

source
IAsyncEnumerable<Int32>

A sequence of values to calculate the average of.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

The average of the sequence of values.

Exceptions

source is null.

The sum of the elements in the sequence is larger than MaxValue (via the returned task).

source contains no elements (via the returned task).

Applies to

.NET 10 and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided), 10
.NET Standard 2.0 (package-provided)

AverageAsync(IAsyncEnumerable<Double>, CancellationToken)

Source:
AverageAsync.cs

Computes the average of a sequence of values.

public static System.Threading.Tasks.ValueTask<double> AverageAsync(this System.Collections.Generic.IAsyncEnumerable<double> source, System.Threading.CancellationToken cancellationToken = default);

Parameters

source
IAsyncEnumerable<Double>

A sequence of values to calculate the average of.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

The average of the sequence of values.

Exceptions

source is null.

source contains no elements (via the returned task).

Applies to

.NET 10 and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided), 10
.NET Standard 2.0 (package-provided)

AverageAsync(IAsyncEnumerable<Decimal>, CancellationToken)

Source:
AverageAsync.cs

Computes the average of a sequence of values.

public static System.Threading.Tasks.ValueTask<decimal> AverageAsync(this System.Collections.Generic.IAsyncEnumerable<decimal> source, System.Threading.CancellationToken cancellationToken = default);

Parameters

source
IAsyncEnumerable<Decimal>

A sequence of values to calculate the average of.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

The average of the sequence of values.

Exceptions

source is null.

source contains no elements (via the returned task).

Applies to

.NET 10 and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided), 10
.NET Standard 2.0 (package-provided)