C# Enumerable Average(IEnumerable)

Description

Computes the average of a sequence of Double values.

Syntax


public static double Average(
  this IEnumerable<double> source
)

Parameters

  • source - A sequence of Double 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 ww  .  j a  va2  s.  c om

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.





















Home »
  C# Tutorial »
    System.Linq »




Enumerable