c# - Using statement vs. IDisposable.Dispose() -
it has been understanding using
statement in .net calls idisposable
object's dispose()
method once code exits block.
does using
statement else? if not, seem following 2 code samples achieve exact same thing:
using con new connection() con.open() 'do whatever ' end using dim con new connection() con.open() 'do whatever ' con.dispose()
i give best answer whoever confirms correct or points out wrong , explains why. keep in mind aware classes can different things in dispose()
methods. question whether or not using
statement achieves exact same result calling object's dispose()
method.
using
equivalent of:
try { // code } { obj.dispose(); }
so has benefit of calling dispose()
if unhandled exception thrown in code within block.
Comments
Post a Comment