C# Program to Show the Usage of LINQ Aggregate() Method Last Updated : 26 Jan, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 number of operations for each of the elements in the given collection by keeping the track of the actions that have been done before. For example, the aggregation function is used to calculate the annual rainfall that occurred in 2021 in step with readings collected the entire year. Another example, the product function is used to calculate the product of the values specified in an array. Syntax: result = collection.Aggregate((element1, element2) => element1 operation element2); Here, element1 and element2 point to the two consecutive elements of the collection, the operation is the operation that we want to apply across collection values, and result stores the final answer after applying operations. Example 1: In this program, we have initialized an array of strings and we want to place colon surrounded by whitespace (" : ") between all the elements and then combine all strings with the help of the Linq Aggregate() method. C# // C# program to demonstrate the working of link // Aggregate() method using System; using System.Linq; class GFG{ static public void Main() { // Initializing an array of strings String[] arr = { "GeeksforGeeks", "Java", "C#", "C++", "C" }; // Placing colon using Aggregate() method String str = arr.Aggregate((string1, string2) => string1 + " : " + string2); // Print Console.WriteLine(str); } } OutputGeeksforGeeks : Java : C# : C++ : CExample 2: In this program, we have initialized an array arr of integers and we are calculating the product of arr elements. Here, we have used the asterisk operator between the elements. C# // C# program to demonstrate the working of // link Aggregate() method using System; using System.Linq; class GFG{ static public void Main() { // Initializing an array of strings int[] arr = { 5, 2, 10, 20, 5 }; // Calculating product of arr elements // using Aggregate() method int product = arr.Aggregate((num1, num2) => num1 * num2); // Print the product Console.WriteLine(product); } } Output10000 Comment More infoAdvertise with us Next Article C# Program to Join Multiple Data Sources using LINQ B bhuwanesh Follow Improve Article Tags : C# C# Programs Similar Reads C# Program to Calculate the Sum of Array Elements using the LINQ Aggregate() Method 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: Aggregat 2 min read C# Program to Demonstrate the Example of LINQ Union() Method with StringComparer LINQ is known as Language Integrated Query and it is introduced in .NET 3.5. It gives a feature to .NET languages to create queries to retrieve data from the data source. Here in this article, we will demonstrate the example of the LINQ Union() method with the StringComparer. 1. Union() Method: This 2 min read C# Program to Join Multiple Data Sources using LINQ LINQ is known as Language Integrated Query and it is introduced in .NET 3.5. It provides the ability to .NET languages to create queries to retrieve data from the data source. In this article, we will discuss how to join multiple data sources using LINQ. Here data source means list. So we are using 4 min read C# Program to Demonstrate the Example of LINQ Intersect() Method with OrderBy() Method LINQ is known as Language Integrated Query and it is introduced in .NET 3.5. It provides the power to .NET languages to create queries to retrieve data from the data source. In this article we will demonstrate the example of the LINQ intersect() method with OrderBy() method. 1. intersect() Method: T 3 min read C# Program to Demonstrate the IList Interface In C# IList interface is an interface that belongs to the collection module where we can access each element by index. Or we can say that it is a collection of objects that are used to access each element individually with the help of an index. It is of both generic and non-generic types. Its implem 3 min read C# Program to Demonstrate the IDictionary Interface IDictionary Interface is an interface that belongs to the collection module where we can access the elements by keys. Or we can say that the IDictionary interface is a collection of key/value pairs. It is available for both generic and non-generic types collection. Here each pair must contain a uniq 3 min read Like