An array is a data structure that contains several variables of the same type. An array is declared using a type:
Type[] Arrayname;
The following example creates a one-dimensional, multidimensional, and jagged array:
1 classTestarraysclass2 {3 Static voidMain ()4 {5 //Declare a single-dimensional array6 int[] Array1 =New int[5];7 8 //Declare and set array element values9 int[] Array2 =New int[] {1,3,5,7,9 };Ten One //Alternative Syntax A int[] Array3 = {1,2,3,4,5,6 }; - - //Declare A and dimensional array the int[,] multiDimensionalArray1 =New int[2,3]; - - //Declare and set array element values - int[,] MultiDimensionalArray2 = {{1,2,3}, {4,5,6 } }; + - //Declare a jagged array + int[] Jaggedarray =New int[6][]; A at //Set the values of the first array in the jagged array structure -jaggedarray[0] =New int[4] {1,2,3,4 }; - } -}
Array overview
The array has the following properties:
An array can be one-dimensional, multidimensional, or interleaved.
The default value of a numeric array element is set to zero, and the default value of the reference element is set to NULL.
A jagged array is an array of arrays, so its elements are reference types and are initialized to null.
The index of the array is zero-based: The index of an array with n elements is from 0 to n-1.
An array element can be any type, including an array type.
An array type is a reference type derived from an abstract base type array. Because this type implements IEnumerable and IEnumerable, you can use foreach iterations for all arrays in C #.
C # arrays