C# Enumerable Sum(IEnumerable)

Description

Computes the sum of a sequence of Decimal values.

Syntax


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

Parameters

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

Returns

returns The sum of the values in the sequence.

Example

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


/*from  ww  w .ja  va 2  s  . co  m*/
using System;
using System.Linq;
using System.Collections.Generic;
public class MainClass{
  public static void Main(String[] argv){  

    List<float> numbers = new List<float> { 43.68F, 1.5F, 58.7F, 6.5F };

    float sum = numbers.Sum();

    Console.WriteLine("The sum of the numbers is {0}.", sum);
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Linq »




Enumerable