1 // 2 // This tests checks out field access to arrays 3 // 4 using System; 5 6 struct A { 7 public int a; 8 } 9 10 class Y { 11 public object a; 12 } 13 14 class X { 15 static A [] a_single = new A [10]; 16 static A [,] a_double = new A [10,10]; 17 static Y [] o_single = new Y [10]; 18 static Y [,] o_double = new Y [10,10]; 19 FillOne()20 static void FillOne () 21 { 22 a_single [0].a = 1; 23 } 24 FillSingle()25 static void FillSingle () 26 { 27 int i; 28 29 for (i = 0; i < 10; i++){ 30 a_single [i].a = i + 1; 31 } 32 } 33 FillDouble()34 static void FillDouble () 35 { 36 int i, j; 37 38 for (i = 0; i < 10; i++) 39 for (j = 0; j < 10; j++) 40 a_double [i,j].a = i * j; 41 } 42 FillObject()43 static void FillObject () 44 { 45 int i; 46 47 for (i = 0; i < 10; i++){ 48 o_single [i] = new Y (); 49 o_single [i].a = (i + 1); 50 } 51 } 52 FillDoubleObject()53 static void FillDoubleObject () 54 { 55 int i, j; 56 57 for (i = 0; i < 10; i++) 58 for (j = 0; j < 10; j++){ 59 o_double [i,j] = new Y (); 60 o_double [i,j].a = i * j; 61 } 62 } 63 TestSingle()64 static int TestSingle () 65 { 66 int i; 67 68 for (i = 0; i < 10; i++){ 69 if (a_single [i].a != i + 1) 70 return 1; 71 } 72 return 0; 73 } 74 TestDouble()75 static int TestDouble () 76 { 77 int i, j; 78 79 for (i = 0; i < 10; i++){ 80 for (j = 0; j < 10; j++) 81 if (a_double [i,j].a != (i *j)) 82 return 2; 83 } 84 85 return 0; 86 } 87 TestObjectSingle()88 static int TestObjectSingle () 89 { 90 int i; 91 92 for (i = 0; i < 10; i++){ 93 if ((int)(o_single [i].a) != i + 1) 94 return 1; 95 } 96 return 0; 97 } 98 TestObjectDouble()99 static int TestObjectDouble () 100 { 101 int i, j; 102 103 for (i = 0; i < 10; i++){ 104 for (j = 0; j < 10; j++) 105 if (((int)o_double [i,j].a) != (i *j)) 106 return 2; 107 } 108 109 return 0; 110 } 111 Main()112 public static int Main () 113 { 114 FillSingle (); 115 FillDouble (); 116 FillObject (); 117 FillDoubleObject (); 118 119 if (TestSingle () != 0) 120 return 1; 121 122 if (TestDouble () != 0) 123 return 2; 124 125 if (TestObjectSingle () != 0) 126 return 3; 127 128 if (TestObjectDouble () != 0) 129 return 4; 130 131 Console.WriteLine ("test passes"); 132 return 0; 133 } 134 } 135