class PassingRefByRef
{
static void Change(ref int[] pArray)
{
// Both of the following changes will affect the original variables:
pArray[0] = 888;
pArray = new int[5] { -3, -1, -2, -3, -4 };
System.Console.WriteLine("Inside the method, the first element is: {0}", pArray[0]);
Console.ReadLine();
}
static void Main()
{
int[] array = { 2, 3, 6, 7 };
System.Console.WriteLine("The No Before Calling the ,The first element is{0}", array[0]);
int[] arr = { 1, 4, 5 };
System.Console.WriteLine("Inside Main, before calling the method, the first element is: {0}", arr[0]);
Change(ref arr);
System.Console.WriteLine("Inside Main, after calling the method, the first element is: {0}", arr[0]);
Console.ReadLine();
}
}
No comments:
Post a Comment