Hello everyone,
Here is my test program. I want to confirm that when we pass an out variable into a function, we just pass a reference, no additional copy is made?
[Code]
class Program
{
struct Foo
{
public int abc;
}
static void Test(out Foo f)
{
f.abc = 200;
return;
}
static void Main(string[] args)
{
Foo f1;
f1.abc = 100;
Test(out f1);
// output 200
Console.WriteLine(f1.abc);
return;
}
}
[/Code]
thanks in advance,
George
George GeorgePosted Jun 11, 2008, 10:55 PM
So great Fernando!
regards,
George
Fernando SotoPosted Jun 11, 2008, 10:46 PM
Hi George;
The out argument is very much like the ref argument with the following differences.
1. Does not need to be assigned a value before going to the function.
2. Must be assigned before leavin the function.
It is a reference to the memoryt location of the variable that is passed in and not a copy of the value.
Fernando