An enthusiastic, adaptive, and fast-learning person with a broad and acute interest in the discovery of new innovative drugs, I particularly enjoy collaborating with scientists from different disciplines to develop new skills and solve new challenges.
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
Liked By
Write Answer
What is Aggregate Function in LINQ?
Join MindStick Community
You have need login or register for voting of answers or question.
Ravi Vishwakarma
24-Sep-2021An 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