C# Enumerable Average(IEnumerable)
Description
Computes the average of a sequence of Single values.
Syntax
public static float Average(
this IEnumerable<float> source
)
Parameters
source
- A sequence of Single values to calculate the average of.
Returns
Returns The average of the sequence of values.
Example
The following code example demonstrates how to use Average(IEnumerable) to calculate an average.
// w w w . jav a 2s . c o m
using System;
using System.Linq;
using System.Collections.Generic;
public class MainClass{
public static void Main(String[] argv){
List<int> grades = new List<int> { 7, 9, 10, 3, 8 };
double average = grades.Average();
Console.WriteLine("The average grade is {0}.", average);
}
}
The code above generates the following result.