(1)
void Fun(int[] Arr)
{
Arr[0] = 888; // This change affects the original element.
Arr = new int[5] {-3, -1, -2, -3, -4}; // This change is local.
// Because two different refernece is created
System.Console.WriteLine("the first element is: {0}", Arr[0]);
}
static void Main()
{
int[] arr = {1, 4, 5};
Fun(ref arr); // Call above method
}
In this case two reference is created. Ref1 and Ref2 are both are pointed
to same object. You can change Reference point object by "New" Keyword.
(2)
static void Fun(ref int[] Arr) {
// Both of the following changes will affect the original variables:
Arr[0] = 888;
Arr = new int[5] {-3, -1, -2, -3, -4};
System.Console.WriteLine("the first element is: {0}", pArray[0]);
}
static void Main() {
int[] arr = {1, 4, 5};
Fun(ref arr);
}
Above case only one reference is created. "New" keyword is
change original object.