11.2. One-Dimensional Arrays

A one-dimensional array is basically a single-column table; elements in the table can be accessed with an index, and all the elements belong to the same data type. Elements in an array always begin with an index of 0. Arrays are declared using [] brackets and are initialized using the new operator in both C# and Java. Let's look at array declaration and initialization in both languages.

Although both languages share similarities, there is a slight difference in initializing arrays. Java has two ways to declare an array; the [] brackets can follow either the data type or the variable name. In C#, the brackets cannot follow the variable name.

A one-dimensional array is initialized in C# this way:

 Int[] arr Int arr[] ...

Get .NET for Java Developers: Migrating to C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.