Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / tests / test-36.cs
1 //
2 // This program excercises invoking foreach on structures
3 // that implement GetEnumerator
4 //
5
6 using System;
7 using System.Collections;
8 struct X {
9         int [] a;
10         
11         public IEnumerator GetEnumerator ()
12         {
13                         a = new int [3] { 1, 2, 3};
14                         return a.GetEnumerator ();
15         }
16 }
17
18 class Y {
19         static X x;
20
21         public static int Main ()
22         {
23                 int total = 0;
24                 x = new X ();
25
26                 foreach (object a in x){
27                         total += (int) a;
28                 }
29
30                 if (total != 6)
31                         return 1;
32
33                 total = 0;
34
35                 foreach (object a in new X ()){
36                         total += (int) a;
37                 }
38                 if (total != 6)
39                         return 3;
40                         
41                 total = 0;
42                 
43                 //
44                 // implicit block
45                 //
46                 foreach (object a in x)
47                         total += (int) a;
48                 if (total != 6)
49                         return 2;
50                 
51                 return 0;
52         }
53 }
54