Interviews3 answers
Can you explain brief about Aggregate() extension method in LINQ?
3 Answers
http://www.dotnetperls.com/aggregate
Munesh SharmaPosted Jun 16, 2015, 7:52 AM EDT
http://www.dotnetperls.com/aggregate
Munesh SharmaPosted Jun 16, 2015, 7:52 AM EDT
The delegate for the Aggregate extension method accepts two integer arguments and returns an integer value representing the sum of both input parameters. The Aggregate extension method loops through each element of the list and performs the operation returned by the delegate passed in.
Alternatively, and instead of using lambda expressions, we could have used anonymous methods to write an inline delegate:
foreach (List l in lstUserData)
{
lstSums.Add(l.Aggregate(delegate(int sum, int elmnt) { return sum elmnt;} ));
}
Bhabani PrasadPosted May 21, 2014, 4:14 AM EDT


