There are two different forms of
using
*
The
using statement
which requires parentheses:
using (MyClass mc = new MyClass())
{
...
}
The system will automatically call Dispose for the variable when the block of code is exited in any way: fall through, exception,
break
,
continue
,
throw
, or
return
.
The
using declaration
:
{
...
using MyClass mc = new MyClass();
...
}
The variable will be Disposed when the code exits the scope in which the variable is declared (he enclosing curly brackets, usually) in the same way as for the
using statement
.
* Well, three - there is also the using directive
which appear at the top of the file and creates aliases.