Consider this method
public static void NumberList(params int[] numbers)
{
foreach (int list in numbers)
{
Console.WriteLine(list);
}
}
I can call this method and supply seperated single integers or just one array with several integers. Within the method scope they will be placed into an array called numbers (right?) where I can continue to manipulate them.
// Works fine
var arr = new int[] { 1, 2, 3};
NumberList(arr);
But if I want to call the method and supply it arrays instead, I get an error. How do you enable arrays for params?
// Results in error
var arr = new int[] { 1, 2, 3};
var arr2 = new int[] { 4, 5, 6 };
NumberList(arr, arr2);