eol
[mcs.git] / tests / test-iter-07.cs
blob051f00f4e7191a1bc93ee576b752ec0748495b73
1 // Compiler options: -langversion:default
3 using System;
4 using System.Collections;
6 public class Test
8 public IEnumerable Foo (int a)
10 try {
11 try {
12 yield return a;
13 } finally {
14 Console.WriteLine ("Hello World");
17 Console.WriteLine ("Next block");
19 try {
20 yield return a * a;
21 } finally {
22 Console.WriteLine ("Boston");
24 } finally {
25 Console.WriteLine ("Outer finally");
28 Console.WriteLine ("Outer block");
29 yield break;
33 class X
35 static int Main ()
37 Test test = new Test ();
39 ArrayList list = new ArrayList ();
40 foreach (object o in test.Foo (5))
41 list.Add (o);
43 if (list.Count != 2)
44 return 1;
45 if ((int) list [0] != 5)
46 return 2;
47 if ((int) list [1] != 25)
48 return 3;
50 IEnumerable a = test.Foo (5);
52 IEnumerator b = a as IEnumerator;
53 if (b != null) {
54 if (b.MoveNext ())
55 return 4;
58 IEnumerator c = a.GetEnumerator ();
59 if (!c.MoveNext ())
60 return 5;
61 if ((int) c.Current != 5)
62 return 6;
63 if (!c.MoveNext ())
64 return 7;
65 if ((int) c.Current != 25)
66 return 8;
68 IEnumerator d = a.GetEnumerator ();
70 if ((int) c.Current != 25)
71 return 9;
72 if (!d.MoveNext ())
73 return 10;
74 if ((int) c.Current != 25)
75 return 11;
76 if ((int) d.Current != 5)
77 return 12;
79 if (c.MoveNext ())
80 return 13;
82 ((IDisposable) a).Dispose ();
83 return 0;