using Statement : using « Statement « C# / CSharp Tutorial






using has a second form that is called the using statement.

It has these general forms:

using (obj) {
    // use obj 
    }
    
    using (type obj = initializer) {
    // use obj 
    }
  1. obj is an object that is being used inside the using block.
  2. In the first form, the object is declared outside the using statement.
  3. In the second form, the object is declared within the using statement.
  4. When the block concludes, the Dispose() method (defined by the System.IDisposable interface) will be called on obj.
  5. The using statement applies only to objects that implement the System.IDisposable interface.








4.10.using
4.10.1.using
4.10.2.Demonstrate the using directive
4.10.3.Demonstrate a using alias
4.10.4.using alias directive
4.10.5.using Statement
4.10.6.IDisposable and the using Keyword