Re: Difference between 'out' and 'ref' parameters.



Thanks for your answer, that has helped a lot.

There does seem to be another difference though,

this is legal (Compiler allows it)

private int DoStuff(ref string x)
{
x = x + ":";
return -1;
}

wheras this will not compile:

private int DoStuff(out string x)
{
x = x + ":";
return -1;
}

(says " 'Use of unassigned local vairable 'x' ")

This, however is fine:

private into DoStuff(out string x)
{
x = "1";
return -1;
}

So you can't pass a value INTO a method using a 'out' parameter like you can
with a 'ref' parameter. (?) I guess that's why its called 'out' :-)

Chris


.



Relevant Pages