MoreEnumerableAggregateRightTSource, TAccumulate, TResult(IEnumerableTSource, TAccumulate, FuncTSource, TAccumulate, TAccumulate, FuncTAccumulate, TResult) Method

Applies a right-associative accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value. This operator is the right-associative version of the AggregateTSource, TAccumulate, TResult(IEnumerableTSource, TAccumulate, FuncTAccumulate, TSource, TAccumulate, FuncTAccumulate, TResult) LINQ operator.

Definition

Namespace: MoreLinq
Assembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
C#
public static TResult AggregateRight<TSource, TAccumulate, TResult>(
	this IEnumerable<TSource> source,
	TAccumulate seed,
	Func<TSource, TAccumulate, TAccumulate> func,
	Func<TAccumulate, TResult> resultSelector
)

Parameters

source  IEnumerableTSource
Source sequence.
seed  TAccumulate
The initial accumulator value.
func  FuncTSource, TAccumulate, TAccumulate
A right-associative accumulator function to be invoked on each element.
resultSelector  FuncTAccumulate, TResult
A function to transform the final accumulator value into the result value.

Type Parameters

TSource
The type of the elements of source.
TAccumulate
The type of the accumulator value.
TResult
The type of the resulting value.

Return Value

TResult
The transformed final accumulator value.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableTSource. 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).

Remarks

This operator executes immediately.

Example

C#
var numbers = Enumerable.Range(1, 5);
int result = numbers.AggregateRight("6", (a, b) => $"({a}/{b})", str => str.Length);
The result variable will contain 21.

See Also