AsyncEnumerableExtensionsAverageAsyncTSource(IAsyncEnumerableTSource, FuncTSource, UBinarySize, CancellationToken) Method

Asynchronously computes the average of a sequence of UBinarySize values that are obtained by invoking a transform function on each element of the input sequence.

Definition

Namespace: Ookii
Assembly: Ookii.BinarySize.Async (in Ookii.BinarySize.Async.dll) Version: 1.2.0+20f0bdf981c7baf115c68ccab612b1a031efcb4d
C#
public static ValueTask<UBinarySize> AverageAsync<TSource>(
	this IAsyncEnumerable<TSource> source,
	Func<TSource, UBinarySize> selector,
	CancellationToken cancellationToken = default
)

Parameters

source  IAsyncEnumerableTSource
A sequence of values to calculate the average of.
selector  FuncTSource, UBinarySize
A transform function to apply to each element.
cancellationToken  CancellationToken  (Optional)
The optional cancellation token to be used for canceling the sequence at any time.

Type Parameters

TSource
The type of the elements of source.

Return Value

ValueTaskUBinarySize
A task that represents the asynchronous operation. The result of the task is the average of the values in the sequence.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IAsyncEnumerableTSource. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Exceptions

ArgumentNullExceptionsource or selector is .
InvalidOperationExceptionsource contains no elements.

See Also