Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / tests / test-188.cs
1 //
2 // Test that the foreach statement generated by mcs invokes the Dispose()
3 // method even if the enumerator class returned by GetEnumerator () does not
4 // implement IDisposable.
5 //
6
7 using System;
8
9 public class Enumerator {
10
11         int counter;
12
13         public Enumerator () {
14                 counter = 3;
15         }
16
17         public bool MoveNext () {
18                 return (counter -- > 0);
19         }
20
21         public char Current {
22                 get {
23                         return 'a';
24                 }
25         }
26 }
27
28 class RealEnumerator : Enumerator, IDisposable {
29
30         Coll c;
31
32         public RealEnumerator (Coll c) {
33                 this.c = c;
34         }
35
36         public void Dispose () {
37                 c.disposed = true;
38         }
39 }
40
41 public class Coll {
42
43         public bool disposed;
44
45         public Enumerator GetEnumerator () {
46                 return new RealEnumerator (this);
47         }
48 }
49
50 class Test {
51
52         public static int Main(String[] args)
53         {
54                 Coll coll = new Coll ();
55                 foreach (char c in coll) {
56                 }
57                 return (coll.disposed ? 0 : 1);
58         }
59 }