using (SomeClass obj= new SomeClass()) { obj.DoSomething(); } to { // limits scope of obj SomeClass obj= new SomeClass(); try { obj.DoSomething(); } finally { // Check for a null resource. if (obj!= null) // Call the object's Dispose method. ((IDisposable)obj).Dispose(); } }
Quote: The using keyword has two major uses: As a directive, when it is used to create an alias for a namespace or to import types defined in other namespaces. See using Directive. As a statement, when it defines a scope at the end of which an object will be disposed. See using Statement.
The using keyword has two major uses:
As a directive, when it is used to create an alias for a namespace or to import types defined in other namespaces. See using Directive.
As a statement, when it defines a scope at the end of which an object will be disposed. See using Statement.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)