C# Arrays
C# Arrays
C# Arrays
int[] myArray;
This statement declares an array of integers.
Since arrays are objects they must be instantiated with the new
operator
int[] myArray = new int[5];
This statement instantiates an array named myArray that holds 5 integers.
We may omit the size of the array, if the assigned values amount
represents the size.
Multidimensional Arrays
An array can have multiple dimensions. A multidimensional array
is declared as follows:
type[, , … ,] arrayName = new type[size1, …, sizeN];
int x = jaggedArray[2][3];
This code assigns the value of 6 to the newly declared variable x
Arrays Properties
Various properties and methods are provided to work with arrays,
Length and Rank are examples. Dot syntax is used to access them.
For example:
Strings
Working with Strings