CSharp examples for LINQ:IEnumerable
Computing nine factorial with LINQ
using System;//from www . j a v a2s . c om using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { // Generate a sequence of integers from 9 .. 1. var factors = Enumerable.Range(1, 9).Reverse(); // Accumulate a running total (aggregate) of each factor multiplied by the next factor. int factorial = factors.Aggregate((runningTotal, nextFactor) => runningTotal * nextFactor); Console.WriteLine("9 factorial (9!) is {0}", factorial); } }