C# Enumerable Sum(IEnumerable>)

Description

Computes the sum of a sequence of nullable Int64 values.

Syntax


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

Parameters

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

Example

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


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

    long?[] points = { null, 10, };

    long? sum = points.Sum();

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

  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Linq »




Enumerable