Average

suggest change
var numbers = new[] {1,2,3,4};

var averageNumber = numbers.Average();
Console.WriteLine(averageNumber);
// 2.5

This method calculates the average of a sequence of numbers. The decimal separator in the printed value follows the current culture.

var cities = new[] {
    new {Population = 1000},
    new {Population = 2000},
    new {Population = 4000}
};

var averagePopulation = cities.Average(c => c.Population);
Console.WriteLine(averagePopulation);
// 2333.33...

This method calculates the average of a sequence using a selector. The decimal separator follows the current culture.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents