C# Enumerable Sum(IEnumerable>)

Description

Computes the sum of a sequence of nullable Decimal values.

Syntax


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

Parameters

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

Example

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


/*from   w w w.ja  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, 0, 92.83F, null, 10.0F, 3.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