using System; namespace using_test { class myDisposable : IDisposable { string m_name; public myDisposable(string name) { m_name = name; } public void Dispose() { Console.WriteLine("{0} is being disposed", m_name); } } class Program { public static void dTest1() { Console.WriteLine("dTest1 >> started."); using(myDisposable foo = new myDisposable("Adam")) { Console.WriteLine("dTest1 >> return."); return; } Console.WriteLine("dTest1 >> you can not read this."); } public static void dTest2() { Console.WriteLine("dTest2 >> started."); using(myDisposable foo = new myDisposable("Bertil")) { Console.WriteLine("dTest2 >> in using statement."); } Console.WriteLine("dTest2 >> done using."); return; Console.WriteLine("dTest2 >> you can not read this."); } public static void dTest3() { Console.WriteLine("dTest3 >> started."); myDisposable foo = new myDisposable("Caesar"); Console.WriteLine("dTest3 >> done testing."); return; } public static void Main(string[] args) { Console.WriteLine("Main >> Starting dTest1!"); dTest1(); Console.WriteLine("Main >> Starting dTest2!"); dTest2(); Console.WriteLine("Main >> Starting dTest3!"); dTest3(); Console.WriteLine("Main >> Done testing!"); Console.WriteLine(); Console.Write("Press any key to continue . . . "); Console.ReadKey(true); } } }