How to get the number of elements in a two-dimensional array?
int[,] array = new int[,] {{1,2,3},{4,5,6},{7,8,9}};//Define a 2D array with 3 rows and 3 columnsint row = ;//Get the dimension, here refers to the number of rowsint col = (1);//Get the number of elements in the specified dimension, which is the number of columns. (0 is the first dimension, 1 represents the second dimension)int col = (0)+1;//Get the index upper limit of the specified dimension, add a 1 to the total number, which represents the number of rows in the two-dimensional arrayint num = ;//Get the length of the entire two-dimensional array,That is, the number of all elements
According to the above, we can verify the form of a multidimensional array by yourself, and use a loop to traverse the array, such as the following four-dimensional array:
int[,,,] arr = new int[9, 8, 7, 6];
;//Return to 4(0);//Return to 9(1);//Return to 8(2);//Return to 7(3);//Return to 6(0)+1;//Return to 9;//return3024
I don't need to explain the remaining loops to loop through the array and operate them, so I will operate according to the above numbers.
This is what this article in C# describes the number of rows and columns of a two-dimensional array and the length of each dimension of a multi-dimensional array. I hope it will be helpful to everyone's learning and I hope everyone will support me more.