Consider this method
public static void NumberList(params int[] numbers) { foreach (int list in numbers) { Console.WriteLine(list); } }
I can call this method and provide separate single integers or just one array with several integers . Within the scope of the method, they will be placed in an array called numbers (on the right?), Where can I continue to manipulate them.
// Works fine var arr = new int[] { 1, 2, 3}; NumberList(arr);
But if I want to call a method and provide its arrays, I get an error message. How to enable arrays for params ?
// Results in error var arr = new int[] { 1, 2, 3}; var arr2 = new int[] { 4, 5, 6 }; NumberList(arr, arr2);
Faloude
source share