Cainiao notes-multi-dimensional array and multi-dimensional array of notes
1. Two-dimensional array
Equivalent to a table, Syntax: int [,] arr = new int [2, 3];
The access element is similar to accessing a cell, subscript [I, j]: [row, column]
GetLength (): This method obtains the dimension array of the array. The subscript starts from 0.
Traverse output:
1 int [,] arr = new int [6, 6]; 2 3 // GetLength (): Get the length of a dimension of the array 4 for (int I = 0; I <arr. getLength (0); I ++) 5 {6 for (int j = 0; j <arr. getLength (1); j ++) 7 {8 arr [I, j] = 6; 9 Console. write (arr [I, j]); 10} 11 Console. writeLine (); 12}View Code
2. Staggered Array
It is essentially a one-dimensional array, but the elements in the array are also a one-dimensional array with no length specified and not instantiated.
Note:
Creation Syntax:
Int [] [] arr = new int [3] [];
Assignment:
Arr [0] = new int [] {3, 6 };
Traverse the elements in the array in the staggered array:
1 for (int I = 0; I <arr2.Length; I ++) 2 {3 int [] arr3 = arr2 [I]; 4 if (arr3! = Null) // judge that the array stored in the array cannot be null 5 {6 for (int j = 0; j <arr3.Length; j ++) 7 {8 Console. writeLine (arr3 [j]); 9} 10} 11}View Code
Summary:
Declare an array. If the data type is the reference data type, the element in the array is null by default if no value is assigned to the array.
If this element is null, no error will be reported if the Console. WriteLine () is similar to the operation output. If you want to traverse and change it, an error will be reported:
Object reference is not set to the object instance