C# Program to Calculate the Sum of Array Elements using the LINQ Aggregate() Method Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Given an array of integers, now we calculate the sum of array elements. So we use the Aggregate() method of LINQ. This method applies a function to all the elements of the source sequence and calculates a cumulative result and return value. This method is overloaded in three different ways: Aggregate<TSource, TAccumulate, TResult>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TResult>): It applies an accumulator function on the specified sequence. Here, the seed value is used to define the starting accumulator value, and the function is used to select the final result value.Aggregate<TSource, TAccumulate>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>): It applies an accumulator function on the specified sequence. Here, the specified seed value is used to define the starting accumulator value.Aggregate<TSource>(IEnumerable<TSource>, Func<TSource, TSource, TSource>): It applies an accumulator function on the specified sequence.Example: Input: { 34, 27, 34, 5, 6 } Output: Sum = 106 Input: { 3, 4, 27, 34, 15, 26, 234, 123 } Output: Sum = 466Approach: 1. Create and initialize an array of integer type 2. Now find the sum of the array using the Aggregate() function. sum = arr.Aggregate((element1,element2) => element1 + element2);3. Display the sum of the elements of the array Example: C# // C# program to finding the sum of the array elements // using Aggregate() Method using System; using System.Linq; class GFG{ static void Main(string[] args) { // Creating and initializing the array // with integer values int[] arr = { 1, 2, 3, 14, 5, 26, 7, 8, 90, 10}; int sum = 0; // Finding the sum of the elements of arr // using Aggregate() Method sum = arr.Aggregate((element1, element2) => element1 + element2); // Displaying the final output Console.Write("Sum is : " + sum); } } Output: Sum is : 166 Comment More infoAdvertise with us Next Article C# Program to Show the Usage of LINQ Aggregate() Method R raghu135ram Follow Improve Article Tags : C# C# Programs CSharp LINQ Similar Reads C# Program to Show the Usage of LINQ Aggregate() Method In LINQ, the aggregation function is the function that serves the purpose of calculating one value from a collection of values. Or we can say that the Aggregate() method is used to perform aggregation operations on the values of a collection. In simple words, the Aggregate() method implements a numb 2 min read C# Program to Find the Index of Even Numbers using LINQ Given an array, now our task is to find the index value of the even numbers present in the given array using LINQ. LINQ is known as Language Integrated Query and was introduced in .NET 3.5. It gives the power to .NET languages to generate queries to retrieve data from the data source. So to do this 2 min read C# Program to Divide Sequence into Groups using LINQ Given a sequence, now our task is to divide the given sequence into groups using LINQ. So to this task first we generate a sequence then we select the elements from the given sequence and then group them together. Approach: 1. In C#, we can use LINQ by including the "System.Linq" namespace in our pr 2 min read C# Program For Producing a Filtered Sequence of Elements that Contain Only One Property of Given Data Given a list that contains the details of the students, now we produce a filtered sequence of elements that contain only one property of each Student. So we use the following method of LINQ to solve the given problem: 1. Aggregate() method: This method is used to perform aggregation operations on th 4 min read C# Program to Split a String Collections into Groups Given a collection of strings and you are required to split them into groups using C#. The standard query operator contains GroupBy grouping operator using which we can split a collection of strings easily. The working of the GroupBy operator is similar to the SQL GroupBy clause. It is used to retur 3 min read How to Calculate the Cumulative Sum of Elements in an Array using JavaScript? In this article, we are going to learn to calculate the cumulative sum of elements in an array using JavaScript. The cumulative sum of elements in an array is a new array where each element represents the sum of all preceding elements, including itself, in the original array.There are several method 4 min read Like