Use Aggregate and Sum in CSharp
Description
The following code shows how to use Aggregate and Sum.
Example
//from w w w . j a v a2 s . com
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
public static void Main() {
IEnumerable<int> intSequence = Enumerable.Range(1, 10);
foreach (int item in intSequence)
Console.WriteLine(item);
int sum = intSequence.Aggregate(0, (s, i) => s + i);
Console.WriteLine(sum);
}
}
The code above generates the following result.