CSharp examples for LINQ:IEnumerable
Aggregate Data Sources
using System;/*w w w . ja va2 s. com*/ using System.Collections.Generic; using System.Linq; using System.Text; class MainClass { static void Main(string[] args) { int[] ds1 = { 11, 23, 37, 49, 143 }; Console.WriteLine("Standard aggregation methods"); Console.WriteLine("Average: {0}", ds1.Average()); Console.WriteLine("Count: {0}", ds1.Count()); Console.WriteLine("Max: {0}", ds1.Max()); Console.WriteLine("Min: {0}", ds1.Min()); Console.WriteLine("Sum: {0}", ds1.Sum()); Console.WriteLine("\nCustom aggregation"); Console.WriteLine(ds1.Aggregate((total, elem) => total += elem)); string[] ds2 = { "Oracle", "pear", "PLSQL" }; Console.WriteLine("\nString concatenation aggregation"); Console.WriteLine(ds2.Aggregate((len, elem) => len += elem)); } }