If you want to use multiple objects of the same type, you can use a set and an array.
1. array declaration and initialization
There are many methods to declare and initialize arrays.
int[] myArray;myArray = new int[4];int[] myArray = new int[4];int[] myArray = new int[4]{2,3,4,5};int[]myArray = new int[]{2,3,4,5};int[]myArray = new {2,3,4,5};
2. Mostly array declarations
int[,] myArray=new int[3,6];//……
Many methods are available for Array initialization.
3. Sawtooth Array
The method for traversing a jagged array is as follows.
int[][] myArray = new int [3][];myArray[0] = new int[2]{3,5};myArray[1] = new int[5]{1,2,3,4,5};myArray[2] = new int[3]{3,4,5};for(int row=0 ; row<myArray.Length ; row++ ){for(int element=0 ; element<myArry[row].Length ; element++ ){//.....}}
4. array class
Using square brackets to create an array is the representation of C # using the array class. When C # syntax is used in the background, a new class derived from the abstract base class array class is created.
4.1 create an array
The array class is an abstract class, so you cannot use constructors to create arrays. You can use the C # syntax and createinstance () to create an array.
Array myArrar = Array.CreateInstance(typeof(int), 5); for (int i = 0; i < 5; i++) myArrar.SetValue(3 + i, i); for (int i = 0; i < 5; i++) Console.Write(myArrar.GetValue(i)+" ");
5. array covariant
The array supports covariant, indicating that the array can be declared as the base class.