Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / tests / test-28.cs
1 using System.Collections;
2 abstract class A {
3         protected abstract int this [int a] { get; }
4
5         public int EmulateIndexer (int a)
6         {
7                 return this [a];
8         }
9 }
10
11 class B : A {
12         protected override int this [int a] { get { return a;}  }
13
14         public int M ()
15         {
16                 return this [0];
17         }
18         
19 }
20 class X {
21         int v1, v2;
22         
23         int this [int a] {
24                 get {
25                         if (a == 0)
26                                 return v1;
27                         else
28                                 return v2;
29                 }
30
31                 set {
32                         if (a == 0)
33                                 v1 = value;
34                         else
35                                 v2 = value;
36                 }
37         }
38
39         public static int Main ()
40         {
41                 X x = new X ();
42
43                 x [0] = 1;
44                 if (x.v1 != 1)
45                         return 1;
46
47                 if (x [0] != 1)
48                         return 2;
49
50                 B bb = new B ();
51
52                 if (bb.EmulateIndexer (10) != 10)
53                         return 3;
54
55                 //
56                 // This tests that we properly set the return type for the setter
57                 // use pattern in the following indexer (see bug 36156)
58                 Hashtable a = new Hashtable ();
59                 int b = (int) (a [0] = 1);
60                 if (b != 1)
61                         return 4;
62                 return new B ().M ();
63         }
64 }