C# Enumerable Sum(IEnumerable>)

Description

Computes the sum of a sequence of nullable Int32 values.

Syntax


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

Parameters

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

Example

The following code example demonstrates how to use Sum(IEnumerable) to sum the values of a sequence.


/*www  .  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){  

    float?[] points = { null, 0, 9.83F, null, 1.0F, 3.46F, 8.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