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

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -