ExtensionMethod.NET Home of 820 C#, Visual Basic, F# and Javascript extension methods

Product

Computes a product of all elements in the sequence.

Source

public static class MathExtensionMethods
{ 
    public static int Product(this IEnumerable<int> values)
    {
       return values.Aggregate((a, b) => a * b);
    }
}

Example

Func<int,int> fac = n => Enumerable.Range(1, n).Product();

Author: Edmondo Pentangelo

Submitted on: 4 feb 2009

Language: C#

Type: System.Collections.Generic.IEnumerable<T>

Views: 2862