C# program to calculate the sum of array elements using the LINQ Aggregate() method
//C# program to calculate the sum of array elements
//using the Linq Aggregate() method.
using System;
using System.Linq;
class LinqDemo
{
static void Main(string[] args)
{
int[] values = { 10, 8, 2, 2, 7, 4};
int sum = 0;
sum = values.Aggregate((val1, val2) => val1 + val2);
Console.WriteLine("Sum is : "+sum);
}
}
Output
Sum is : 33
Press any key to continue . . .
Table of Contents