LINQ Aggregate() FunctionIn LINQ, Aggregate() function is used to perform the operation on each item of the list. The Aggregate() function performs the action on the first and second elements and then carry forward the result. For the next operation, it will consider the previous result and the third element and then carryforwards, etc. Syntax of LINQ Aggregate function in C#In the above syntax, we take two elements 1 and 2 to perform the addition and make 3 then it take the previous result 3 and next element 3 and perform the addition to make the 6 to the next element 4 and result will be 10. Now we will show the example of using the linq Aggregate () function in C# to calculate the product of all the numbers in the integer array. Syntax of LINQ Aggregate function in C#In the above examples, there is an integer array Num. We calculated the product of all the elements present in the given array. For this, we have to specify a Lambda Expression. In the Lambda Expression, we took two input parameters, "a" and "b." And on the righthand side, we multiply the parameters of input. Now we would be getting the product of all the numbers. These are the steps that will describe the functionality of the above example.
In the same way, we are concatenating the list of items (a,b,c,d) in separated string in LINQ. When we execute the above LINQ Aggregate () function, we will get the results as shown below: Output
Next TopicLINQ Sorting Operators
