One-dimensional array definition: int[] Myar;
one-dimensional array declarations and their initialization:
Declare the array and set the length of the array: int[] myarr=new int[] (5);
If you initialize an array with curly braces, you can also not specify the size of the array, because the compiler automatically counts the number of elements: int[] myarr=new int[]{4,7, 11, 2};
There is also a more streamlined form of using C # translators. Jiao can declare and initialize an array at the same time with curly braces: int[] MyArray = {4, 7, 11, 2};
Iterate through elements in a group:
for (int i = 0 San Zhi i < myarr.length; i++)
{
Console.writel⊥ne (Myarray[il]);
}
foreach (Var val in Myaarr)
{
Console.writel⊥ne (Myarray[il]);
}
Multidimensional Array Definitions:
int[,] arr=new int[3,3] ();//definition and initialization of multidimensional arrays
Multidimensional Array Assignment:
Arr[0,0]=1;
arr[0,1]=2;
arr[0,2]=3;
arr[1,0]=4;
arr[1,1]=5;
arr[1,2]=6;
arr[2,0]=7;
arr[2,1]=8;
arr[2,2]=9;
Simplified way to define arrays and initialize and assign values: int[,] arr={{1,2,3},{4,5,6},{7, 8, 9}}
Array value assignment and the acquiring party Array Intarray =array.createinstance (typeof (int) 5) for (int i = 0; I <5; i++{
Intarray.setvalue (, i);
}
For (int i = 0;i<5; i++)
{
Console.WriteLine (Intarray1.getvaue (i));
}
Array replication:
int intArray2 = (int[]) intarry1.clone ();
In addition to using the clone () method, you can create a shallow copy using the fine feather four Ⅱ⑽ method. But the clone method and the Copy party
Method has one important difference: Theclone method creates a new array, and the copy method must pass the same order and have sufficient elements of its own
There are arrays.
Array sort: array.sort ();
Array definition, initialization and its properties