After learning C + + basic knowledge, now learning C # is a lot simpler, but still a little different, such as C # two-dimensional array of definitions, declarations are different.
Here's a look at what's different:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Collections;
Namespace two-dimensional array {class Program {static void Main (string[] args) {//two-D array:
Definition and initialization of regular two-dimensional arrays int[,] Arr = new int[2, 5] {1, 2, 3, 5, 6}, {1, 2, 3, 4, 5}};
Console.WriteLine ("Output of a regular two-dimensional array:");
for (int i = 0; i < 2; ++i) {for (int j = 0; j < 5; ++j) {
Console.Write (Convert.ToString (arr[i,j]) + "");
} Console.WriteLine ();
} Console.WriteLine ("----------------"); Irregular two-dimensional array int [] arr = new int [3][];
Represents an array containing three one-dimensional arrays arr[0] = new int[5]{1,2,3,4,5};
ARR[1] = new int [2]{0,1};
ARR[2] = new int[0] {};
Console.WriteLine ("Output Method One:"); for (int i = 0; i< 2; ++i) {for (int j = 0; j < 5; ++j) {Console.Write (Conv Ert.
ToString (Arr[i, J]) + "");
} Console.WriteLine ();
} Console.WriteLine ();
Console.WriteLine ("Output Method II:"); for (int II = 0; II < arr. Length; ++II)//arr.
Length is 3 to see that arr is an array containing three one-dimensional arrays {foreach (int j in Arr[ii]) {
Console.Write (j+ "");
} Console.WriteLine ();
} console.readkey ();
}
}
}
From the above C # code can be seen, C # has two different ways to define two-dimensional arrays, of course, the distinction between the above has been made very clear, do not understand the words copy down to run again, contrast.
and C + + in defining a two-dimensional array, of course, must write out the ' Number of columns 'of the array, and C # 's irregular two-dimensional array can be understood to hold arrays of one-dimensional arrays