2009-02-10 Jeffrey Stedfast <fejj@novell.com>
[mono-project/dkf.git] / mcs / tests / test-iter-09.cs
blob32312cb4ede1a82a91fc54503280a9a80c7544b7
1 using System;
2 using System.Collections;
4 public class Tester
6 string[] ABC = { "A", "B", "C" };
7 // D
8 string [,] EFGH = { { "E", "F" }, { "G", "H"}};
9 // I
10 ArrayList al = new ArrayList ();
12 public Tester ()
14 al.Add ("J");
15 al.Add ("K");
18 public System.Collections.IEnumerator GetEnumerator()
20 foreach (string s in ABC){
21 if (s == null)
22 throw new Exception ();
23 else
24 yield return s;
27 yield return "D";
28 foreach (string s in EFGH){
29 if(s == null)
30 throw new Exception ();
31 else
32 yield return s;
35 yield return "I";
36 foreach (string s in al){
37 if (s == null)
38 throw new Exception ();
39 else
40 yield return s;
43 yield return "L";
48 class Test
50 public static int Main()
52 Tester tester = new Tester();
53 string [] list = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L" };
54 int top = 0;
56 foreach (string s in tester){
57 if (s != list [top]){
58 Console.WriteLine ("Failure, got {0} expected {1}", s, list [top]);
59 return 1;
61 top++;
63 if (top != list.Length){
64 Console.WriteLine ("Failure, expected {0} got {1}", list.Length, top);
66 Console.WriteLine ("Success");
67 return 0;