Aggregation operations (C#)

An aggregation operation computes a single value from a collection of values. An example of an aggregation operation is calculating the average daily temperature from a month's worth of daily temperature values.

The following illustration shows the results of two different aggregation operations on a sequence of numbers. The first operation sums the numbers. The second operation returns the maximum value in the sequence.

Illustration that shows LINQ aggregation operations.

The standard query operator methods that perform aggregation operations are listed in the following section.

Methods

Method name description C# query expression syntax More information
Aggregate Performs a custom aggregation operation on the values of a collection. Not applicable. Enumerable.Aggregate
Queryable.Aggregate
Average Calculates the average value of a collection of values. Not applicable. Enumerable.Average
Queryable.Average
Count Counts the elements in a collection, optionally only those elements that satisfy a predicate function. Not applicable. Enumerable.Count
Queryable.Count
LongCount Counts the elements in a large collection, optionally only those elements that satisfy a predicate function. Not applicable. Enumerable.LongCount
Queryable.LongCount
Max or MaxBy Determines the maximum value in a collection. Not applicable. Enumerable.Max
Enumerable.MaxBy
Queryable.Max
Queryable.MaxBy
Min or MinBy Determines the minimum value in a collection. Not applicable. Enumerable.Min
Enumerable.MinBy
Queryable.Min
Queryable.MinBy
Sum Calculates the sum of the values in a collection. Not applicable. Enumerable.Sum
Queryable.Sum

See also