ParamsArray

[code language=”csharp”] using System;
using static System.Console;

namespace ParamsArray
{
class Program
{
static void Main(string[] args)
{
double[] array = { 3, 7, 9, 12, 16 };
Average(7);
Average(26, 98);
Average(41.5, 77.6, 98.2, 41.2);
Average(array);
}

static void Average(params double[] nums)
{
double total = 0;
double avg;

foreach (double number in nums)
{
Write("{0} ", number);
total += number;
}

avg = total / nums.Length;
Console.WriteLine("The average is {0}", avg);
Console.WriteLine();
}
}
}
[/code]