In C #, the declaration of an array is an instantiation of the arrays.
Declaration of a one or one-D array
1. Integer array
The following declares a one-dimensional array with 5 integer elements:
int[] array = new INT[5]; The above array contains elements from array[0] to array[4] that have a total of 5 integers. The new operator is used to create an array and initialize the array elements to their default values. In this example, all the array elements are initialized to zero.
2. Array of strings
string[] Stringarray = new STRING[10]; The above array contains elements from stringarray[0] to stringarray[9] totaling 10 characters.
Declaration of a two or two-D array
The syntax format for declaring a two-dimensional array is as follows:
data type [,] array name =new data type [second dimension size, first dimension]; For example, the following declares a two-dimensional array of 5 rows and 3 columns:
int[,] array = new int[5,3];5 refers to the second-dimension size in a two-dimensional array, and the 3 column refers to the first-dimensional size in a two-dimensional array.
Declaration of a three or three-D array
The syntax format for declaring a three-dimensional array is as follows:
Data type [,,] array name =new data type [third dimension size, second dimension size, first dimension size]; For example:
int[,,] array = new int[4,5,3];
Iv. Declaration of jagged arrays
The following declares a one-dimensional array of 5 elements, each of which is a one-dimensional array of integers:
int[][] Jiaoarray = new int[5][]; iterate through jagged arrays:
for (int x = 0; x < jiaoarray.length; × x + +)
{
JIAOARRAY[X] = new INT[4];
}
V. Mixed use of rectangular arrays and jagged arrays
The following code declares a one-dimensional array of three-dimensional arrays of two-dimensional arrays of type int:
int[][,,][,] array;