C# Enumerable Average(IEnumerable>)

Description

Computes the average of a sequence of nullable Single values.

Syntax


public static Nullable<float> Average(
  this IEnumerable<Nullable<float>> source
)

Parameters

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

Example

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


/*from   w ww .  j  a va2s  .  com*/

using System;
using System.Linq;
using System.Collections.Generic;
public class MainClass{
  public static void Main(String[] argv){  
    long?[] longs = { null, 10007L, 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