Aggregate Method

Learn how to apply a function to a collection carrying the result with the Aggregate method.

How to perform an operation carrying the result

The Aggregate method applies a function to a collection, carrying the result to the next element. It aggregates the result of a function. The Aggregate method takes two parameters: a seed and an aggregating function that takes the accumulated value and one element from the collection.

On the first iteration, the Aggregate method executes the aggregating function using the seed and the first element of the collection as parameters. Next, it calls the aggregating function with the previous result as an accumulator and the next element of the collection.

This is the pseudocode of the Aggregate method:

Get hands-on with 1400+ tech skills courses.