String Array:
Using system; Class myclass {static void main () {string [] arr = new string [3] {"AA", "BB", "cc "}; foreach (string s in ARR) console. writeline (s); // AA/BB/CC console. readkey ();}}
Integer array:
Using system; Class myclass {static void main () {int [] arr = {11, 22, 33}; foreach (int I in ARR) console. writeline (I); // 11/22/33 console. readkey ();}}
The number of dimensions can be omitted during initialization. If not, the values must be consistent:
Using system; Class myclass {static void main () {int [] arr = new int [3] {11, 22, 33}; foreach (int I in ARR) console. writeline (I); // 11/22/33 console. readkey ();}}
The statement specifies the dimension at the same time, but does not assign a value for the moment:
Using system; Class myclass {static void main () {int [] arr = new int [3]; foreach (int I in ARR) console. writeline (I); // 0/0/0 arr [0] = 11; arr [1] = 22; arr [2] = 33; foreach (int I in ARR) console. writeline (I); // 11/22/33 console. readkey ();}}
Declare the dimension before determining the dimension when assigning values:
Using system; Class myclass {static void main () {int [] arr; arr = new int [] {11, 22, 33}; foreach (int I in ARR) console. writeline (I); // 11/22/33 console. readkey ();}}
The dimension of the statement can be changed:
Using system; Class myclass {static void main () {int [] arr = new int [3]; arr = new int [4] {11, 22, 33, 44 }; foreach (int I in ARR) console. writeline (I); // 11/22/33/44 console. readkey ();}}
If the variable is used as the array dimension, it must be const:
Using system; Class myclass {static void main () {const int size = 3; int [] arr = new int [size] {11, 22, 33 }; foreach (int I in ARR) console. writeline (I); // 11/22/33 console. readkey ();}}
Two-dimensional array initialization:
Using system; Class myclass {static void main () {int [,] arr = {11, 12, 13, 14}, {,}, {, 34 }}; foreach (int I in ARR) console. writeline (I); console. readkey ();}}
Two-dimensional array assignment:
Using system; Class myclass {static void main () {int [,] arr = new int [3, 4]; arr [0, 0] = 11; arr [0, 1] = 12; arr [] = 13; arr [] = 14; arr [] = 21; arr [] = 22; arr [] = 23; arr [] = 24; arr [] = 31; arr [] = 32; arr [] = 33; arr [] = 34; foreach (int I in ARR) console. writeline (I); console. readkey ();}}
Multi-dimensional array:
Using system; Class myclass {static void main () {int [,] arr = new int [2, 3, 4]; for (INT x = 0; x
Array:
Using system; Class myclass {static void main () {int [] [] arr = new int [3] []; arr [0] = new int [2] {11, 12}; arr [1] = new int [3] {21, 22, 23}; arr [2] = new int [4] {31, 32, 33, 34}; foreach (INT [] ns in ARR) foreach (int n in NS) console. writeline (n); console. readkey ();}}