Using statements and returns

  • Thread starter Thread starter Smokey Grindel
  • Start date Start date
S

Smokey Grindel

If I have a function and inside it have something like this


Using Obj1
Using Obj2
Return Value
End Using
End using

The Using statements still know how to handle the dispose and cleanup
correctly dont they? Or do I have to put the return outside of the using
blocks... I was always under the impression you can return inside of them
and it will still dispose as needed... thanks!
 
If I have a function and inside it have something like this

Using Obj1
Using Obj2
Return Value
End Using
End using

The Using statements still know how to handle the dispose and cleanup
correctly dont they? Or do I have to put the return outside of the using
blocks... I was always under the impression you can return inside of them
and it will still dispose as needed... thanks!

Also note you can do this:

Using Obj1, Obj2
Return Value
End Using

I know it's not the answer to your question (as David beat me to
it :-)), I just thought you might like to know if you didn't already.

Thanks,

Seth Rowe
 
Smokey Grindel said:
If I have a function and inside it have something like this


Using Obj1
Using Obj2
Return Value
End Using
End using

The Using statements still know how to handle the dispose and cleanup
correctly dont they?

Yes.

The code equivalent to those the compiler generates for each 'Using' block
basically looks like that:

\\\
Dim Obj As IDisposable
Try
<Contents of the 'Using' block>
Catch
Finally
Obj.Dispose()
End Try
///
 
Back
Top