Average
suggest changevar 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents