Normalize line endings.
[mono.git] / mcs / tests / dtest-008.cs
1 using System;
2 using System.Collections.Generic;
3
4 // Dynamic statements
5
6 class Disposable : IDisposable
7 {
8         public int Counter;
9
10         public void Dispose ()
11         {
12                 ++Counter;
13         }
14
15         public void Test ()
16         {
17         }
18 }
19
20 public class Test
21 {
22         bool ForEachTest ()
23         {
24                 dynamic d = new List<int> { 5, 10, 7 };
25                 dynamic res = 9;
26                 foreach (var v in d) {
27                         res += v;
28                 }
29
30                 Console.WriteLine (res);
31                 return res == 31;
32         }
33
34         bool UsingTest ()
35         {
36                 dynamic d = new Disposable ();
37                 try {
38                         using (d) {
39                                 d.VV ();
40                         }
41                 } catch { }
42
43                 if (d.Counter != 1)
44                         return false;
45
46                 try {
47                         using (dynamic u = new Disposable ()) {
48                                 u.VV ();
49                         }
50                 } catch { }
51
52                 if (d.Counter != 1)
53                         return false;
54
55                 return true;
56         }
57
58         public static int Main ()
59         {
60                 var t = new Test ();
61                 if (!t.ForEachTest ())
62                         return 1;
63
64                 if (!t.UsingTest ())
65                         return 2;
66
67                 Console.WriteLine ("ok");
68                 return 0;
69         }
70 }