C# Enumerable Sum(IEnumerable)
Description
Computes the sum of a sequence of Double values.
Syntax
public static double Sum(
this IEnumerable<double> source
)
Parameters
source
- A sequence of Double 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.
//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){
List<float> numbers = new List<float> { 4.68F, 1.25F, 53.7F, 61.5F };
float sum = numbers.Sum();
Console.WriteLine("The sum of the numbers is {0}.", sum);
}
}
The code above generates the following result.