The syntax for array declaration is the same in C# as in Java, except for one difference “ when declaring an array, Java permits putting the square brackets either in front of or behind the array's type. C# only allows the former “ Putting the square brackets after an array identifier will cause a compilation error. [3]
Both the following declarations are okay in Java:
However, only int []MyArray; is legal in C#. Other than that, the syntax for array declaration, instantiation, and initialization are identical in C# and Java as far as 1D arrays are concerned . Examples are shown below as a refresher and for reference.
Beyond 1D arrays, C# supports two types of multi-dimensional arrays “ rectangular arrays and jagged arrays. Because Java's multi-dimensional arrays do not map directly into either category, I have chosen to compare Java's implementation with the simpler rectangular arrays. |