An Aggregate function takes more than two arguments and works on the requirement. there are many aggregate functions in LINQ
SOME function of LINQ
SUM() return the sum of a collection
MIN() return the minimum of collection
MAX() returns the maximum collection
COUNT() return the length of the collection
Average() return is the average of a collection
Aggregate() returns the value as needed from a collection
Example
using System; using System.Linq; using System.Collections.Generic;
class MyProgram { static void Main(string[ ] args) {
int[] intAry = {45,78,5,896,4,5,8,65,99,66,55,88,5,558,56,55,45,23}; var Sum = intAry.Where(x => x%2 == 0).Sum(); Console.WriteLine('Sum of array : ' + Sum);
var Min = intAry.Min(); Console.WriteLine('Min of array : ' + Min);
var Max = intAry.Max(); Console.WriteLine('Max of array : ' + Max);
var Count = intAry.Count(); Console.WriteLine('Length of array : ' + Count);
var Avg = intAry.Average(); Console.WriteLine('Average of array : ' + Avg);
var Aggregate = intAry.Aggregate((a,b) => a+b); Console.WriteLine('Aggregate function of array : ' + Aggregate);
} }
Output
Sum of array : 1754
Min of array : 4
Max of array : 896
Length of array : 18
Average of array : 119.77777777777777
Aggregate function of array : 2156
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
An Aggregate function takes more than two arguments and works on the requirement. there are many aggregate functions in LINQ
SOME function of LINQ
Example
Output