2 // Tests the using statement implementation
7 class MyDispose : IDisposable {
10 public void Dispose ()
17 public static int Main ()
19 MyDispose copy_a, copy_b, copy_c;
22 // Test whether the two `a' and `b' get disposed
24 using (MyDispose a = new MyDispose (), b = new MyDispose ()){
34 Console.WriteLine ("Nested using clause disposed");
37 // See if the variable `b' is disposed if there is
38 // an error thrown inside the using block.
42 using (MyDispose c = new MyDispose ()){
44 throw new Exception ();
51 Console.WriteLine ("Disposal on finally block works");
54 // This should test if `a' is non-null before calling dispose
57 using (MyDispose d = null){
60 Console.WriteLine ("Null test passed");
62 MyDispose bb = new MyDispose ();
66 if (bb.disposed == false)
69 Console.WriteLine ("All tests pass");