C# Enumerable Average(IEnumerable>)

Description

Computes the average of a sequence of nullable Int32 values.

Syntax


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

Parameters

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

Example

The following code example demonstrates how to use Average(IEnumerable) to calculate an average.


//w w w. j a v  a  2 s.  co  m
using System;
using System.Linq;
using System.Collections.Generic;
public class MainClass{
  public static void Main(String[] argv){  
    long?[] longs = { null, 11231237L, 37L, 123123123123L };
    double? average = longs.Average();
    Console.WriteLine("The average is {0}.", average);

  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Linq »




Enumerable