C# Enumerable Average(IEnumerable)

Description

Enumerable Average(IEnumerable)Computes the average of a sequence of Decimal values.

Syntax


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

Parameters

Enumerable.Average(IEnumerable) has the following parameters.

  • source - A sequence of Decimal values to calculate the average of.

Returns

Enumerable.Average(IEnumerable) method returns The average of the sequence of values.

Example

The following code example demonstrates how to use Average(IEnumerable) to calculate the average of a sequence of values.


//from w  ww.  j  a  v a 2s.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.





















Home »
  C# Tutorial »
    System.Linq »




Enumerable