Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Program
- {
- public static void Main()
- {
- Console.WriteLine(Sum(1, 2, 3, 4, 5));
- Console.WriteLine(SumWithoutParams(new int[] {1, 2, 3, 4, 5}));
- }
- public static int Sum(params int[] numbers)
- {
- var sum = 0;
- foreach (var n in numbers) { sum += n; }
- return sum;
- }
- public static int SumWithoutParams(int[] numbers)
- {
- var sum = 0;
- foreach (var n in numbers) { sum += n; }
- return sum;
- }
- }
Add Comment
Please, Sign In to add comment