You're passing a reference to the array that is going to be filled up by the method, here's an example to show how that that works
public static void FillArrayWithA(char[] arr)
{
for(var i = 0;i<arr.Length;i++)
{
arr[i]='A';
}
}
public static void Main(string[] args)
{
var newArr = new char[10];
FillArrayWithA(newArr);
Console.WriteLine(new string(newArr));
}
out and ref are used to modify the actual passed variable, here is an example where that is happening:
public static void NewArrayWithA(out char[] arr)
{
arr = new char[10];
for(var i = 0;i<arr.Length;i++)
{
arr[i]='A';
}
}
public static void Main(string[] args)
{
char[] newArr;
FillArrayWithA(out newArr);
Console.WriteLine(new string(newArr));
}
Unlike in the first example the value held in the variable newArr
is being assigned a variable by the NewArrayWithA
method, the FillArrayWithA
method just modifies the array through the reference passed when the method is called