Mega Code Archive

 
Categories / C# Tutorial / LINQ
 

Simple Anonymous Methods for calculating the mean value

using System; using System.Collections.Generic; using System.ComponentModel;     class MainClass     {         static void Main()         {             Action<IList<double>> printMean = delegate(IList<double> numbers)                 {                     double total = 0;                     foreach (double value in numbers)                     {                         total += value;                     }                     Console.WriteLine(total / numbers.Count);                 };             double[] samples = { 1.5, 2.5, 3, 4.5 };             printMean(samples);         }     }