2010-04-07 Jb Evain <jbevain@novell.com>
[mcs.git] / tests / test-188.cs
blobe33e525582eb067efe4098784f13e8a32bbfc768
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 //
7 using System;
9 public class Enumerator {
11 int counter;
13 public Enumerator () {
14 counter = 3;
17 public bool MoveNext () {
18 return (counter -- > 0);
21 public char Current {
22 get {
23 return 'a';
28 class RealEnumerator : Enumerator, IDisposable {
30 Coll c;
32 public RealEnumerator (Coll c) {
33 this.c = c;
36 public void Dispose () {
37 c.disposed = true;
41 public class Coll {
43 public bool disposed;
45 public Enumerator GetEnumerator () {
46 return new RealEnumerator (this);
50 class Test {
52 public static int Main(String[] args)
54 Coll coll = new Coll ();
55 foreach (char c in coll) {
57 return (coll.disposed ? 0 : 1);