1 // Programmer's Reference: Passing Array Using ref and out
2 public static void MyMethod(out int[] arr
)
4 arr
= new int[10]; // definite assignment of arr
7 public static void MyMethod(ref int[] arr
)
9 arr
= new int[10]; // arr initialized to a different array
15 static public void FillArray(out int[] myArray
)
17 // Initialize the array:
18 myArray
= new int[5] {1, 2, 3, 4, 5}
;
21 static public void Main()
23 int[] myArray
; // Initialization is not required
25 // Pass the array to the callee using out:
26 FillArray(out myArray
);
28 // Display the array elements:
29 Console
.WriteLine("Array elements are:");
30 for (int i
=0; i
< myArray
.Length
; i
++)
31 Console
.WriteLine(myArray
[i
]);