- using System.IO;
- using System;
- class ParameterArrayAsReference
- {
- private static void Main(string[] args)
- {
- int[] valArray =
- {
- 10, 20
- };
- Console.WriteLine("Before Method Call: val1: {0} \t val2: {1}", valArray[0], valArray[1]);
- AddList(ref valArray);
- Console.WriteLine("After Method Call: val1: {0} \t val2: {1}", valArray[0], valArray[1]);
- }
- static void AddList(ref int[] intVals)
- {
- int[] newArray =
- {
- 12, 32
- };
- intVals = newArray;
- }
- }
Output:Before Method Call: val1: 10 val2: 20
After Method Call: val1: 12 val2: 32