[sdks] Fix README.md
[mono-project.git] / mcs / tests / test-42.cs
blob1120be6206f1557fdc69c4a32bdca02902dc626d
1 //
2 // This test exercises the various ways in which mutator operators can be
3 // used in C# and the various different scenarios that the compiler would
4 // have to deal with
5 //
6 // variables, linear arrays, multi-dimensional arrays, jagged arrays,
7 // properties, indexers and overloaded ++ and --
8 //
10 class X {
12 public int v, p;
13 public int idx;
15 public int this [int n] {
16 get {
17 idx = n;
18 return v;
20 set {
21 idx = n;
22 v = value;
26 public int P {
27 get {
28 return p;
31 set {
32 p = value;
38 class Z {
39 int v;
41 public Z P {
42 get {
43 return null;
46 set {
50 static public Z operator ++ (Z v)
52 v.v++;
53 return v;
57 class Y {
59 static int p_pre_increment (X x)
61 return ++x.P;
64 static int p_post_increment (X x)
66 return x.P++;
69 static int i_pre_increment (X x)
71 return ++x [100];
74 static int i_post_increment (X x)
76 return x [14]++;
79 static Z overload_increment (Z z)
81 return z++;
84 static Z overload_pre_increment (Z z)
86 return ++z;
89 static Z ugly (Z z)
91 return z.P++;
95 // Tests the ++ and -- operators on integers
97 static int simple (int i)
99 if (++i != 11)
100 return 1;
101 if (--i != 10)
102 return 2;
103 if (i++ != 10)
104 return 3;
105 if (i-- != 11)
106 return 4;
107 return 0;
110 static int arrays ()
112 int [] a = new int [10];
113 int i, j;
115 for (i = 0; i < 10; i++)
116 a [i]++;
118 for (i = 0; i < 10; i++)
119 if (a [i] != 1)
120 return 100;
122 int [,] b = new int [10,10];
123 for (i = 0; i < 10; i++){
124 for (j = 0; j < 10; j++){
125 b [i,j] = i * 10 + j;
126 if (i < 5)
127 b [i,j]++;
128 else
129 ++b [i,j];
133 for (i = 0; i < 10; i++){
134 for (j = 0; j < 10; j++){
135 if (b [i,j] != i * 10 + (j + 1))
136 return 101;
140 return 0;
143 public static int Main ()
145 X x = new X ();
146 int c;
148 if ((c = simple (10)) != 0)
149 return c;
151 if (i_pre_increment (x) != 1)
152 return 5;
154 if (x.idx != 100)
155 return 6;
157 if (i_post_increment (x) != 1)
158 return 7;
160 if (x.idx != 14)
161 return 8;
163 if (p_pre_increment (x) != 1)
164 return 9;
166 if (x.p != 1)
167 return 10;
169 if (p_post_increment (x) != 1)
170 return 10;
172 if (x.p != 2)
173 return 11;
175 Z z = new Z();
177 overload_increment (z);
179 arrays ();
181 return 0;