S
Schizoid Man
Hello,
I am having some difficulty understanding the nuances of passing arrays as
parameters, and exactly how pass-by-reference is different from
pass-by-value for this particular example:
static void Main(string[] args)
{
int[] Test = { 1, 2, 3 };
Modify(Test);
Console.WriteLine(Test[0]);
Console.ReadLine();
}
static void Modify(int[] TestArray)
{
TestArray[0] = 4;
}
As far as I can tell, defining the function call as 'Modify(ref Test)' and
the method itself as 'static void Modify(ref int[] TestArray)' will make no
difference to the output of the program.
In this regard is C# similar to VB.Net, where arrays are always
pass-by-value (the trick being to make a copy of the array in the invoked
method)?
Thanks,
Schiz
I am having some difficulty understanding the nuances of passing arrays as
parameters, and exactly how pass-by-reference is different from
pass-by-value for this particular example:
static void Main(string[] args)
{
int[] Test = { 1, 2, 3 };
Modify(Test);
Console.WriteLine(Test[0]);
Console.ReadLine();
}
static void Modify(int[] TestArray)
{
TestArray[0] = 4;
}
As far as I can tell, defining the function call as 'Modify(ref Test)' and
the method itself as 'static void Modify(ref int[] TestArray)' will make no
difference to the output of the program.
In this regard is C# similar to VB.Net, where arrays are always
pass-by-value (the trick being to make a copy of the array in the invoked
method)?
Thanks,
Schiz