C# language

Array declaration:

int[ ] numble;

Create an array:

int[ ] numble=new int [5];

Animal[ ] zoo=new Animal[100];

Animal is a class that must be declared before use;

Initialize the class:

Animal[ ] zoo = new Animal[3]{

new Animal("Wolf"),

new Animal("Lion"),

new Animal("Cat")

};

//The array itself is an object, you must use new to create an instance of the array

Array declaration and initialization:

string[ ]  msg = {"Hello","Bye","How are you"};

string s1 = msg[2];

string s2 = msg[3];//This will cause the overflow number of characters to cross the boundary;

foreach is similar to for, traversing the entire number rent. foreach loops automatically, reading out the array elements with indices from 0 to length

* does not require us to set loop conditions and iteration variables, simpler and safer

The element value read by *foreach is read-only and cannot be modified;

grammar:

int[ ] numble = {1,2,3};

foreach (int x in numble ){

Console.writeline(x);

}

Array methods (functions)

Sort sorts the elements of the number rent

Clear sets the element to the default output value of 0 or null

Clone creates a rental copy

GetLength Gets the number of elements in the specified dimension of the array

IndexOf the index of the first occurrence of a value in the array

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325812326&siteId=291194637