Complete the code to declare a method that accepts a variable number of integer arguments using the correct keyword.
public void PrintNumbers([1] int[] numbers) { foreach (int num in numbers) { Console.WriteLine(num); } }
The params keyword allows a method to accept a variable number of arguments as an array.
Complete the method call to pass multiple integers to the method using the params keyword.
PrintNumbers([1]);When a method uses params, you can pass multiple arguments separated by commas without creating an array explicitly.
Fix the error in the method declaration to correctly use the params keyword for variable arguments.
public void SumNumbers([1] int[] numbers) { int sum = 0; foreach (int num in numbers) { sum += num; } Console.WriteLine(sum); }
The params keyword must be placed before the array parameter to allow variable arguments.
Fill both blanks to declare a method that sums variable integer arguments and returns the total.
public int SumAll([1] int[] numbers) { int total = 0; foreach (int num in [2]) { total += num; } return total; }
The method uses params before the array parameter name 'numbers'. Inside the method, you iterate over 'numbers'.
Fill all three blanks to declare a method that prints each string argument passed using the params keyword.
public void PrintAll([1] string[] [2]) { foreach (string [3] in [2]) { Console.WriteLine([3]); } }
The method uses params before the string array parameter named 'words'. The foreach loop uses 'word' to iterate over 'words'.