Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace MethodWithParams
- {
- class Program
- {
- static void Main(string[] args)
- {
- MethodSum(1, 2, 3, 4, 5, 6);
- MethodSum(1, 2, 3, 4, 5, 6, 4, 7, 8, 9, 7, 5); // can invoke this method with different number of parameters
- }
- static void MethodSum(params int[] numbers)
- {
- int sum = 0;
- for (int i = 0; i < numbers.Length; i++)
- {
- sum += numbers[i];
- }
- Console.WriteLine(sum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement