Merge pull request #1190 from esdrubal/encoder-convert
[mono.git] / mcs / tests / test-null-operator-05.cs
1 using System;
2
3 class CI
4 {
5         public string this [string i] { set { } get { return ""; } }
6         public int? this [int i] { set { } get { return 1; } }
7 }
8
9 class C
10 {
11         static int TestArrayAccess ()
12         {
13                 byte[] arr = null;
14                 var v = arr? [0];
15                 if (v != null)
16                         return 1;
17
18                 long?[] ar2 = null;
19                 var v2 = ar2? [-1];
20                 if (v2 != null)
21                         return 2;
22
23                 var v3 = arr? [0].GetHashCode () ?? 724;
24                 if (v3 != 724)
25                         return 3;
26
27 // TODO: Disabled for now?
28 //        arr? [0] += 2;
29                 return 0;
30         }
31
32         static int TestIndexerAccess ()
33         {
34                 CI ci = null;
35                 var v = ci? ["x"];
36                 if (v != null)
37                         return 1;
38
39                 var v2 = ci? [0];
40                 if (v2 != null)
41                         return 2;
42
43                 var v3 = ci? [0].GetHashCode () ?? 724;
44                 if (v3 != 724)
45                         return 3;
46
47 // TODO: Disabled for now?
48 //       ci? [0] += 3;
49                 return 0;
50         }
51
52         static int Main ()
53         {
54                 int res;
55                 res = TestArrayAccess ();
56                 if (res != 0)
57                         return 10 + res;
58
59                 res = TestIndexerAccess ();
60                 if (res != 0)
61                         return 20 + res;
62
63                 Console.WriteLine ("ok");
64                 return 0;
65         }
66 }