Definition of the array:
is the ability to store any number of data of the same type, each item in the array is called an array item, the array item must be of the same type, each array item has a number called index/subscript, the index of an array (subscript) is a number of type int, the index (subscript) is an array of 0, and then the number of each of the
1. Declaration and assignment of arrays
(1) statement
data type [] variable name;
(2) Assign value
Variable name =new data type [length];
(3) Merger:
data type [] Variable name =new data type [length];
(4) Case:
int []numbers=newint[5]; Defines a number variable, which is an array of data that can hold 5 int types;
2. Read and modify array entries read-read data item
Variable name [index];
From the specified number, the value of an array entry is taken out by number, and the return type is the data item type
-Read Array length
Variable name. length; return type int type
Modify
Variable name [index]= value;
3, array of fixed staying power
Once an array is created, its length is fixed, so the array is suitable for scenarios where the number of data is fixed
4. Array traversal
-to implement an array traversal, you can use the loop
-The loop variable starts at 0 and takes the maximum subscript of the array, that is, the length of the array-1
-In the loop body, use the loop variable as the subscript to remove the value of each item in the array
Case
has an array with the variable named a, output the value of each item in the array for (int i=0; i<a.length;i++) {Console.WriteLine (A[i])
5. Array initializer
string[]str=New string[3];str[0]="a"; str[1]="b"; str[2]="C"; ↓↓↓string[]str=New string[3]{"a","b","C"};------->array initializer ↓↓↓string[]str={"a","b","C"};-----> Simple notation for array initializers, which can only be used in definition sentences
The C # language for front-end learning-arrays