Possible Duplicate:
Passing an IDisposable object by reference causes an error?
Why doesn’t C# allow passing a variable from a using block to a function as ref or out?
This is my code:
using (Form s = new Form())
{
doSomthing(ref s);
}
The function ends before the using block ends, why doesn’t C# let me pass s as ref or out parameter?
usingvariables are treated as readonly, as any reassignment is probably an error. Sincerefallows reassignment, this would also be an issue. At the IL level,outis pretty-much identical toref.However, I doubt you need
refhere; you are already passing a reference to the form, since it is a class. For reference-types, the main purpose of arefwould be to allow you to reassign the variable, and have the caller see the reassignment, i.e.it is not required if you are just talking to the form object:
since it is the same form object.