Something like:
using (IDisposable disposable = GetSomeDisposable())
{
//.....
//......
return Stg();
}
I believe it is not a p
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.