CSharp examples for LINQ:IEnumerable
sum of squares of values via Aggregate
using System;//from w w w. j av a 2 s .c om using System.Collections.Generic; using System.Linq; class FunctionalProgramming { static void Main() { var values = new List<int> {3, 10, 6, 1, 4, 8, 2, 5, 9, 7}; Console.Write("Original values: "); values.Display(); // call Display extension method // sum of squares of values via Aggregate Console.WriteLine("Sum of squares via Aggregate method: " + values.Aggregate(0, (x, y) => x + y * y)); } } // declares an extension method static class Extensions { // extension method that displays all elements separated by spaces public static void Display<T>(this IEnumerable<T> data) { Console.WriteLine(string.Join(" ", data)); } }