returning in the middle of a using block
As several others have pointed out in general this is not a problem.
The only case it will cause you issues is if you return in the middle of a using statement and additionally return the in using variable. But then again, this would also cause you issues even if you didn't return and simply kept a reference to a variable.
using ( var x = new Something() ) {
// not a good idea
return x;
}
Just as bad
Something y;
using ( var x = new Something() ) {
y = x;
}
It's perfectly fine.
You are apparently thinking that
using (IDisposable disposable = GetSomeDisposable())
{
//.....
//......
return Stg();
}
is blindly translated into:
IDisposable disposable = GetSomeDisposable()
//.....
//......
return Stg();
disposable.Dispose();
Which, admittedly, would be a problem, and would make the using
statement rather pointless --- which is why that's not what it does.
The compiler makes sure that the object is disposed before control leaves the block -- regardless of how it leaves the block.