// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; namespace E { public class X : IDisposable { public X() { Console.WriteLine("Constructed"); } public void Dispose() { Console.WriteLine("Disposed"); } } public class Program { public static void Main(string[] args) { using(X x1 = new X()) { using(X x2 = new X()) { Console.WriteLine("Eksempel #1"); } } using(X x1 = new X()) using(X x2 = new X()) Console.WriteLine("Eksempel #2"); using(X x1 = new X()) { Console.WriteLine("before"); using(X x2 = new X()) { Console.WriteLine("Eksempel #3"); } Console.WriteLine("after"); } using(X x1 = new X(),x2 = new X()) { Console.WriteLine("Eksempel #4"); } } } }