Search results
1 wrz 2023 · Pass multidimensional arrays as arguments. You pass an initialized multidimensional array to a method in the same way that you pass a one-dimensional array. The following code shows a partial declaration of a print method that accepts a two-dimensional array as its argument.
To access an element of a two-dimensional array, you must specify two indexes: one for the array, and one for the element inside that array. Or better yet, with the table visualization in mind; one for the row and one for the column (see example below).
In a multidimensional array, each element of the array is also an array. In this tutorial, we will learn about multidimensional arrays in C# using the example of two-dimensional arrays.
C# supports multidimensional arrays up to 32 dimensions. The multidimensional array can be declared by adding commas in the square brackets. For example, [,] declares two-dimensional array, [, ,] declares three-dimensional array, [, , ,] declares four-dimensional array, and so on.
C# allows you to define an array with multiple dimensions. When an array has more than one dimension, it is called a multidimensional array. The following example declares a two-dimensional array (or 2D array) of two rows and three columns.
24 maj 2010 · With multidimensional arrays, you can use the same method to iterate through the elements, for example: int [,] numbers2D = new int [3, 2] { { 9, 99 }, { 3, 33 }, { 5, 55 } }; foreach (int i in numbers2D) { System.Console.Write (" {0} ", i); } The output of this example is: 9 99 3 33 5 55.
Learn about multidimensional arrays in C#. Discover how to create, initialize, and manipulate 2D and 3D arrays with clear examples and best practices.