C # Array Summary
1. Definition of arrays
An array is actually a set of data elements of the same type represented by a variable name.
An array is a reference type.
All elements of an array must be of the same type.
Once the array is created, the size is fixed. C # does not support dynamic arrays.
2. Array declarations
One-dimensional array declaration: int[] arrary = new int[];
Arrary[0] = 1;
ARRARY[1] = 1;
Or as follows:
int[] arrary = new Int[3] {n-only};
Two-dimensional array declaration: int[,] arrary = new int[,];
int[,] arrary = new Int[,]{{10,1},{11,1},{2,21}}
Jagged array declaration: int[][] arrary = new int[2][];
ARRARY[1] = 1;
ARRARY[2] = 2;
3. Indexing and initialization of arrays
The index of each dimension in the array starts at 0.
The index inside the square brackets follows the array name.
When an array is created, each element is automatically initialized to the default value of the type. For predefined types, the integer default value is 0, the float default is 0.0, the bool type defaults to False, and the reference type default value is null.
4. Code examples for multidimensional arrays
var arrary = new int[,]{{0,1,2},{10,11,12}};
for (int i = 0; I <arrary. GetLength (0); i++)
for (int j = 0; J < Arrary. GetLength (1); J + +)
Console.WriteLine ("Arrary[{0},{1}" is {2} ", I, J, Arrary[i, J]); )
An array instance is an object that inherits from System.arrary. The getlength (int n) method is to get the length of the specified dimension in the array.
5.Clone method
Cloning an array of value types results in 2 independent arrays.
Cloning a reference-type array produces two arrays that point to the same object.
The Clone method returns a reference to the type object, which must be cast to the array type. The code example is as follows:
Int[] Arrary = {n/a};
Int[] arr = (int[]) arrary. Clone ();//must be strengthened to convert (int[])
C # Array Summary