The using Statement

Updated: there is no inner try...catch in the outer finally block, readers who mentioned it are right! Thanks!

Together with the lock statement, the using keyword is also relatively mysterious:

using (IDisposable instance = ...)

{

    //do something

}

 

is equal to: 

 

IDisposable instance = ...;

try

{

    //do something

}

finally

{

    if (instance != null)

    {

        instance.Dispose();

    }

}

                             

2 Comments

Comments have been disabled for this content.