using statement

We can use the using statement to simplify the finally block and try ... catch statement.

The following:


using (StreamReader reader = File.OpenText ("file.txt"))
{
...
}

is precisely equivalent to:


StreamReader reader = File.OpenText ("file.txt");
try
{
   ...
}
finally
{
   if (reader != null) 
      ((IDisposable)reader).Dispose();
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.