Aggregate and Sum : Aggregate « LINQ « C# / C Sharp






Aggregate and Sum

 

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);
    }
}

 








Related examples in the same category

1.Use Aggregate on an array
2.Use Aggregate on an array with tenary operator
3.Aggregate Prototype