Aggregation Function in LINQ Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In LINQ, aggregation functions are those functions which are used to calculate a single value from the collection of the values. Real life example of aggregation function is calculating the annual rainfall occurred in 2018 according to readings collected whole year. Another example, the sum function is used to find the sum of the values present in the given array or sequence. Following is the list of the methods that are used to perform aggregation operations: Method Description Aggregate It performs, a custom aggregation operation on the values of a collection. Average It calculates the average value of a collection of values. Count It counts the elements in a collection, optionally only those elements that satisfy a predicate function. LongCount It counts the elements in a large collection, optionally only those elements that satisfy a predicate function. Max It determines the maximum value in a collection. Min It determines the minimum value in a collection. Sum It calculates the sum of the values in a collection. Example 1: CSharp // C# program to illustrate how to // find the sum of the given sequence using System; using System.Linq; public class GFG { // Main Method static public void Main() { int[] sequence = {20, 40, 50, 68, 90, 89, 99, 9, 57, 69}; Console.WriteLine("The sum of the given sequence is: "); // Finding sum of the given sequence // Using Sum function int result = sequence.Sum(); Console.WriteLine(result); } } Output: The sum of the given sequence is: 591 Example 2: CSharp // C# program to illustrate how to // find the minimum and maximum value // from the given sequence using System; using System.Linq; public class GFG { // Main Method static public void Main() { int[] sequence = {201, 39, 50, 9, 7, 99}; // Display the Sequence Console.WriteLine("Sequence is: "); foreach(int s in sequence) { Console.WriteLine(s); } // Finding the minimum value // from the given sequence // Using Min function int result1 = sequence.Min(); Console.WriteLine("Minimum Value is: {0}", result1); // Finding the maximum value // from the given sequence // Using Max function int result2 = sequence.Max(); Console.WriteLine("Maximum Value is: {0}", result2); } } Output: Sequence is: 201 39 50 9 7 99 Minimum Value is: 7 Maximum Value is: 201 Reference: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/aggregation-operations Comment More infoAdvertise with us Next Article LINQ | Join (Inner Join) A ankita_saini Follow Improve Article Tags : C# CSharp LINQ Similar Reads Cross Join in LINQ In LINQ, the cross join is a process in which the elements of two sequences are combined with each other means the element of first sequence or collection is combined with the elements of another sequence or collection without any key selection or any filtering condition and the number of elements p 5 min read LINQ | Join (Inner Join) In LINQ, Join operators are used for integrating two data source into one data source which shares some common attributes. For example, in a bank, the manager has two lists, the first list contains the personal details and another list contains the home loan details. Now the manager wants to create 5 min read LINQ | How to find aggregate of the given sequence? In LINQ, you can create your own custom aggregation operation using the Aggregate method. This method allows you to perform a custom aggregation operation on the values of a collection or a sequence. It does not support query syntax in C# and VB.Net languages but can support method syntax in both la 3 min read LINQ | Aggregate Operators | LongCount In LINQ, a Count operator is available to count the elements of the given sequence or collection. But there is a drawback of count operator, i.e, it only works for the MaxValue, i.e, 2147483647, if you try to more than this value then it will throw an OverflowException. So this drawback is overcome 3 min read LINQ | Concatenation Operator | Concat The concatenation is a process in which one sequence is appended into another sequence. In LINQ, the concatenation operation contains only one operator that is known as Concat. It is used to append two same types of sequences or collections and return a new sequence or collection. It does not suppor 3 min read C# | Union of SortedSet to a collection SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.UnionWith(IEnumerable<T>) method is used to modify the current SortedSet<T> object so that it contains all elements that are present in either 2 min read Like