Merge pull request #1861 from saper/home-override
[mono-project.git] / mcs / tests / test-iter-05.cs
blobcb35b7aeaf4649cf963a4cf0170fae26c62739b0
1 // Compiler options: -langversion:default
3 //
4 // Use
6 using System;
7 using System.Collections;
9 class X {
10 static IEnumerable GetIt ()
12 List l = new List (3);
13 l.Add (1);
14 l.Add (2);
15 l.Add (3);
17 foreach (int i in l)
18 yield return i;
21 public static int Main ()
23 int total = 0;
24 foreach (int i in GetIt ()) {
25 Console.WriteLine ("Got: " + i);
26 total += i;
29 return total == 6 ? 0 : 1;
33 public class List : IEnumerable {
35 int pos = 0;
36 int [] items;
38 public List (int i)
40 items = new int [i];
43 public void Add (int value)
45 items [pos ++] = value;
48 public MyEnumerator GetEnumerator ()
50 return new MyEnumerator(this);
53 IEnumerator IEnumerable.GetEnumerator ()
55 return GetEnumerator ();
58 public struct MyEnumerator : IEnumerator {
60 List l;
61 int p;
63 public MyEnumerator (List l)
65 this.l = l;
66 p = -1;
69 public object Current {
70 get {
71 return l.items [p];
75 public bool MoveNext()
77 return ++p < l.pos;
80 public void Reset()
82 p = 0;