1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| class Program { static void Main() { int sum1 = SumParameters(1); int sum2 = SumParameters(1, 2); int sum3 = SumParameters(3, 3, 3); int sum4 = SumParameters(2, 2, 2, 2);
Console.WriteLine(sum1); Console.WriteLine(sum2); Console.WriteLine(sum3); Console.WriteLine(sum4); }
static int SumParameters(params int[] values) { int total = 0; foreach (int value in values) { total += value; } return total; } }
|