| Common errors |
Error description |
Corrected code |
| int numbers[] |
The brackets used to declare the array are placed after the data type, not after the variable identifier |
Int[] numbers; |
|
Int[] numbers;
NUMBERS={42,84,168}; |
If you assign a value to an array after the declaration, you need to use the New keyword and optionally specify a data type . |
Int[] numbers;
Numbers=new int[]{42,84,168}; |
| INT[3] numbers={42,84,168}; |
You cannot specify an array size in a variable declaration |
Int[] numbers={42,84,168}; |
| Int[] Numbers=new int[]; |
Unless you provide an array literal, you must specify the size of the array at initialization time. |
Int[] Number=new int[3]; |
| Int[] Numbers=new int[3]{} |
The array size is specified as 3, but there are no elements in the array literal. The size of the array must match the number of elements in the array literal. |
Int[] Numbers=
New int[3]{42,84,168}; |
|
Int[] Numbers=new int[3];
Console.WriteLine (Numbers[3]); |
The array index starts at zero. Therefore, the index of the last item is 1 smaller than the array length. Note that this is a run-time error, not a compile-time error. |
Int[] Numbers=new int[3];
Console.WriteLine (Numbers[2]); |
|
Int[] Numbers=new int[3];
Numbers[numbrs. length]=42; |
Same as the previous error: you need to subtract one from length to access the last element. Note that this is a run-time error, not a compile-time error. |
Int[] Numbers=new int[3];
Numbers[numbers. length-1]=42; |
|
Int[] numbers;
Console.WriteLine (Numbers[0]); |
The numbers array has not been instantiated, so it is temporarily inaccessible. |
Int[] numbers={42,84};
Console.WriteLine (Numbers[0]); |
|
int[,] numbers=
{{42}. {84,42}}; |
The structure of multidimensional arrays must be consistent |
int[,] numbers={{42,168},{84,42}}; |
|
Int[][] Numbers=
{{42,84}.
{84,42}}; |
A jagged array requires an array of arrays to be instantiated. |
Int[][] numbers={new int[]{42,84},new int[]{84,42}}; |