C# Enumerable Average(IEnumerable)

Description

Computes the average of a sequence of Int32 values.

Syntax


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

Parameters

  • source - A sequence of Int32 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.


/*from   w w w. j ava  2s.  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, 7, 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