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

Fernando Soto44 reputationPosted Jun 11, 2008, 6:46 PM EDT
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
George GeorgeRank #1,736 · 870 reputationPosted Jun 11, 2008, 6:55 PM EDT
So great Fernando!
regards,
George