In class/Microsoft.Build.Tasks/Microsoft.Build.Tasks:
[mcs.git] / tests / test-iter-06.cs
blob1abdcb8cdb80c7f2603fcd2dec9faf0af2308160
1 // Compiler options: -langversion:default
3 using System;
4 using System.Collections;
6 struct S {
7 int j;
9 public IEnumerable Get (int a)
11 Console.WriteLine ("Sending: " + a);
12 yield return a;
13 j = 10;
14 Console.WriteLine ("Sending: " + j);
15 yield return j;
18 public static IEnumerable GetS (int a)
20 yield return 100;
21 yield return a;
22 yield return 1000;
26 class X {
27 IEnumerable Get (int a)
29 yield return 1;
30 yield return 2;
31 yield return a;
34 static IEnumerable GetS (int a)
36 yield return a;
37 yield return a;
38 yield return 1;
41 static int Main ()
43 X y = new X ();
45 int total = 0;
46 foreach (int x in y.Get (5)){
47 total += x;
49 if (total != 8)
50 return 1;
52 total = 0;
53 foreach (int x in GetS (3)){
54 total += x;
56 if (total != 7)
57 return 2;
59 S s = new S();
60 total = 0;
61 foreach (int x in s.Get (100)){
62 Console.WriteLine ("Got: " + x);
63 total += x;
65 if (total != 110)
66 return 3;
68 total = 0;
69 foreach (int x in S.GetS (1)){
70 total += x;
72 if (total != 1101)
73 return 4;
75 Console.WriteLine ("OK");
76 return 0;