AsyncEnumerable.AverageAsync Method
In this article
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
- 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);
static member AverageAsync : System.Collections.Generic.IAsyncEnumerable<Nullable<int64>> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<Nullable<double>>
<Extension()>
Public Function AverageAsync (source As IAsyncEnumerable(Of Nullable(Of Long)), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Nullable(Of Double))
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) |
- 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);
static member AverageAsync : System.Collections.Generic.IAsyncEnumerable<single> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<single>
<Extension()>
Public Function AverageAsync (source As IAsyncEnumerable(Of Single), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Single)
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) |
- 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);
static member AverageAsync : System.Collections.Generic.IAsyncEnumerable<Nullable<single>> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<Nullable<single>>
<Extension()>
Public Function AverageAsync (source As IAsyncEnumerable(Of Nullable(Of Single)), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Nullable(Of Single))
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) |
- 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);
static member AverageAsync : System.Collections.Generic.IAsyncEnumerable<Nullable<double>> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<Nullable<double>>
<Extension()>
Public Function AverageAsync (source As IAsyncEnumerable(Of Nullable(Of Double)), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Nullable(Of Double))
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) |
- 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);
static member AverageAsync : System.Collections.Generic.IAsyncEnumerable<Nullable<int>> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<Nullable<double>>
<Extension()>
Public Function AverageAsync (source As IAsyncEnumerable(Of Nullable(Of Integer)), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Nullable(Of Double))
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) |
- 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);
static member AverageAsync : System.Collections.Generic.IAsyncEnumerable<int64> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<double>
<Extension()>
Public Function AverageAsync (source As IAsyncEnumerable(Of Long), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Double)
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) |
- 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);
static member AverageAsync : System.Collections.Generic.IAsyncEnumerable<Nullable<decimal>> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<Nullable<decimal>>
<Extension()>
Public Function AverageAsync (source As IAsyncEnumerable(Of Nullable(Of Decimal)), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Nullable(Of Decimal))
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) |
- 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);
static member AverageAsync : System.Collections.Generic.IAsyncEnumerable<int> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<double>
<Extension()>
Public Function AverageAsync (source As IAsyncEnumerable(Of Integer), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Double)
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) |
- 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);
static member AverageAsync : System.Collections.Generic.IAsyncEnumerable<double> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<double>
<Extension()>
Public Function AverageAsync (source As IAsyncEnumerable(Of Double), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Double)
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) |
- 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);
static member AverageAsync : System.Collections.Generic.IAsyncEnumerable<decimal> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<decimal>
<Extension()>
Public Function AverageAsync (source As IAsyncEnumerable(Of Decimal), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Decimal)
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) |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Additional resources
In this article
- Definition
- Overloads
- AverageAsync(IAsyncEnumerable<Nullable<Int64>>, CancellationToken)
- AverageAsync(IAsyncEnumerable<Single>, CancellationToken)
- AverageAsync(IAsyncEnumerable<Nullable<Single>>, CancellationToken)
- AverageAsync(IAsyncEnumerable<Nullable<Double>>, CancellationToken)
- AverageAsync(IAsyncEnumerable<Nullable<Int32>>, CancellationToken)
- AverageAsync(IAsyncEnumerable<Int64>, CancellationToken)
- AverageAsync(IAsyncEnumerable<Nullable<Decimal>>, CancellationToken)
- AverageAsync(IAsyncEnumerable<Int32>, CancellationToken)
- AverageAsync(IAsyncEnumerable<Double>, CancellationToken)
- AverageAsync(IAsyncEnumerable<Decimal>, CancellationToken)