IDisposable and the using Keyword : using « Statement « C# / CSharp Tutorial






using System;
   
public class MyClass : IDisposable
{
    public MyClass()
    {
        Console.WriteLine("constructor");
    }
   
    ~MyClass()
    {
        Console.WriteLine("destructor");
    }
   
    public void Dispose()
    {
        Console.WriteLine("implementation of IDisposable.Dispose()");
    }
}
   
public class MainClass
{
    static void Main()
    {
        using(MyClass MyObject = new MyClass())
        {
        }
    }
}








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