[sdks] Fix README.md
[mono-project.git] / mcs / tests / test-52.cs
blob3ba6223a2c0f9c4e5029a618c51518b6760086a6
1 //
2 // Tests the foreach on strings, and tests the implicit use of foreach
3 // to pull the enumerator from the class and identify the pattern to be called
4 //
5 using System;
6 using System.Collections;
8 class Y {
9 int count = 0;
11 public bool MoveNext ()
13 count++;
14 return count != 10;
17 public object Current {
18 get {
19 return count;
24 class X {
26 static string [] a = {
27 "one", "two", "three"
30 public Y GetEnumerator ()
32 return new Y ();
35 public static int Main ()
38 // String test
40 string total = "";
42 foreach (string s in a){
43 total = total + s;
45 if (total != "onetwothree")
46 return 1;
49 // Pattern test
51 X x = new X ();
53 int t = 0;
54 foreach (object o in x){
55 t += (int) o;
57 if (t != 45)
58 return 2;
61 // Looking for GetEnumerator on interfaces test
63 Hashtable xx = new Hashtable ();
64 xx.Add ("A", 10);
65 xx.Add ("B", 20);
67 IDictionary vars = xx;
68 string total2 = "";
69 foreach (string name in vars.Keys){
70 total2 = total2 + name;
73 if ((total2 != "AB") && (total2 != "BA"))
74 return 3;
76 ArrayList list = new ArrayList ();
77 list.Add ("one");
78 list.Add ("two");
79 list.Add ("three");
80 int count = 0;
83 // This test will make sure that `break' inside foreach will
84 // actually use a `leave' opcode instead of a `br' opcode
86 foreach (string s in list){
87 if (s == "two"){
88 break;
90 count++;
92 if (count != 1)
93 return 4;
95 Console.WriteLine ("test passes");
96 return 0;