Array
An array is a data structure that contains several variables of the same type. Arrays are declared by type:
Type [] arrayname;
The following example creates a one-dimensional, multi-dimensional, and staggered array:
C # copyCode
Class testarraysclass
{
Static void main ()
{
// Declare a single-dimen1_array
Int [] array1 = new int [5];
// Declare and set array element values
Int [] array2 = new int [] {1, 3, 5, 7, 9 };
// Alternative syntax
Int [] array3 = {1, 2, 3, 4, 5, 6 };
// Declare a two dimen1_array
Int [,] multidimensionalarray1 = new int [2, 3];
// Declare and set array element values
Int [,] multidimensionalarray2 = {1, 2, 3}, {4, 5, 6 }};
// Declare a jarged Array
Int [] [] jaggedarray = new int [6] [];
// Set the values of the first array in the jarged Array Structure
Jargedarray [0] = new int [4] {1, 2, 3, 4 };
}
}
Array Overview
An array has the following attributes:
Arrays can be one-dimensional, multi-dimensional, or staggered.
The default value of the numeric array element is set to zero, and the default value of the referenced element is set to null.
An interleaved array is an array. Therefore, its element is of the reference type and its initialization is null.
The index of an array starts from zero: The index of an array with n elements ranges from 0 to n-1.
Array elements can be of any type, including arrays.
The array type is derived from the abstract base type array.Reference Type. Because this type implements ienumerable and ienumerable, you can use foreach Iteration for all arrays in C.