2004-08-03 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / tests / 2test-9.cs
1 using System;
2 using System.Collections;
3
4 public class Foo : IDisposable
5 {
6         public readonly int Data;
7
8         public Foo (int data)
9         {
10                 this.Data = data;
11         }
12
13         public bool disposed;
14
15         public void Dispose ()
16         {
17                 disposed = true;
18         }
19 }
20
21 class X
22 {
23         public static IEnumerable Test (int a, int b)
24         {
25                 Foo foo3, foo4;
26
27                 using (Foo foo1 = new Foo (a), foo2 = new Foo (b)) {
28                         yield return foo1.Data;
29                         yield return foo2.Data;
30
31                         foo3 = foo1;
32                         foo4 = foo2;
33                 }
34
35                 yield return foo3.disposed;
36                 yield return foo4.disposed;
37         }
38
39         static int Main ()
40         {
41                 ArrayList list = new ArrayList ();
42                 foreach (object data in Test (3, 5))
43                         list.Add (data);
44
45                 if (list.Count != 4)
46                         return 1;
47                 if ((int) list [0] != 3)
48                         return 2;
49                 if ((int) list [1] != 5)
50                         return 3;
51                 if (!(bool) list [2])
52                         return 4;
53                 if (!(bool) list [3])
54                         return 5;
55
56                 return 0;
57         }
58 }