C# Enumerable Average(IEnumerable)
Description
Computes the average of a sequence of Int64 values.
Syntax
public static double Average(
this IEnumerable<long> source
)
Parameters
source
- A sequence of Int64 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.
/* ww w. j a v a2s .com*/
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, 1 };
double average = grades.Average();
Console.WriteLine("The average grade is {0}.", average);
}
}
The code above generates the following result.