ChangeLog: Updated ChangeLog.
[mono.git] / mcs / tests / 2test-6.cs
1 //
2 // Use
3
4 using System;
5 using System.Collections;
6
7 class X {
8         static IEnumerable GetIt ()
9         {
10                 List l = new List (3);
11                 l.Add (1);
12                 l.Add (2);
13                 l.Add (3);
14                 
15                 foreach (int i in l)
16                         yield return i;
17         }
18         
19         static int Main ()
20         {
21                 int total = 0;
22                 foreach (int i in GetIt ()) {
23                         Console.WriteLine ("Got: " + i);
24                         total += i;
25                 }
26                 
27                 return total == 6 ? 0 : 1;
28         }
29 }
30
31 public class List : IEnumerable {
32
33         int pos = 0;
34         int [] items;
35         
36         public List (int i) 
37         {
38                 items = new int [i];
39         }
40         
41         public void Add (int value) 
42         {
43                 items [pos ++] = value;
44         }
45         
46         public MyEnumerator GetEnumerator ()
47         {
48                 return new MyEnumerator(this);
49         }
50         
51         IEnumerator IEnumerable.GetEnumerator ()
52         {
53                 return GetEnumerator ();
54         }
55         
56         public struct MyEnumerator : IEnumerator {
57                 
58                 List l;
59                 int p;
60                 
61                 public MyEnumerator (List l) 
62                 {
63                         this.l = l;
64                         p = -1;
65                 }
66                 
67                 public object Current {
68                         get {
69                                 return l.items [p];
70                         }
71                 }
72                 
73                 public bool MoveNext() 
74                 {
75                         return ++p < l.pos;
76                 }
77
78                 public void Reset() 
79                 {
80                         p = 0;
81                 }
82         }
83 }