C# Enumerable Sum(IEnumerable>)

Description

Computes the sum of a sequence of nullable Single values.

Syntax


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

Parameters

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

Example


//from  ww  w  .  j a  v  a 2 s. c  o m
using System;
using System.Linq;
using System.Collections.Generic;
public class MainClass{
  public static void Main(String[] argv){  

    float?[] points = { null, 10, 9.83F, null, 100.0F, 37.46F, 81.1F };

    float? sum = points.Sum();

    Console.WriteLine("Total points earned: {0}", sum);

  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Linq »




Enumerable