Find the Mathematical Product of Double Array in C#

If you have an array of doubles (or floats) in C#, there is no built-in method (that I know of) to find the product of those numbers. The product is where you multiply all of the numbers together. I needed this, so I created a utility method that does this simple operation. See below.

public static double Product(params double[] values)
{
	if (values.Length == 0)
		return 0.0;
 
	double result = 1.0;
 
	foreach (double value in values)
		result *= value;
 
	return result;
}

Leave a Reply