2010-05-31 Jb Evain <jbevain@novell.com>
[mcs.git] / tests / dtest-008.cs
blobe2d8e7e35167bc96932f2f55905913d230c942cf
1 using System;
2 using System.Collections.Generic;
4 // Dynamic statements
6 class Disposable : IDisposable
8 public int Counter;
10 public void Dispose ()
12 ++Counter;
15 public void Test ()
20 public class Test
22 bool ForEachTest ()
24 dynamic d = new List<int> { 5, 10, 7 };
25 dynamic res = 9;
26 foreach (var v in d) {
27 res += v;
30 Console.WriteLine (res);
31 return res == 31;
34 bool UsingTest ()
36 dynamic d = new Disposable ();
37 try {
38 using (d) {
39 d.VV ();
41 } catch { }
43 if (d.Counter != 1)
44 return false;
46 try {
47 using (dynamic u = new Disposable ()) {
48 u.VV ();
50 } catch { }
52 if (d.Counter != 1)
53 return false;
55 return true;
58 public static int Main ()
60 var t = new Test ();
61 if (!t.ForEachTest ())
62 return 1;
64 if (!t.UsingTest ())
65 return 2;
67 Console.WriteLine ("ok");
68 return 0;