To display all elements from a 2 dimensional array in C#, you can use nested loops to iterate through each element of the array and print it to the console.
Here's an example of how to do it:
main.cs258 chars11 lines
In this example, we first create a 2 dimensional array called myArray
with 3 rows and 3 columns. We then use nested loops to iterate through each element of the array. The outer loop iterates through the rows (i
), while the inner loop iterates through the columns (j
).
Inside the nested loops, we use Console.Write
to print each element of the array to the console. We add a space after each element so that the output is nicely formatted. After printing all the elements in a row, we use Console.WriteLine
to move to the next line and start printing the next row.
When we run this code, we'll see the following output:
main.cs18 chars4 lines
This displays all the elements of the 2 dimensional array in a nicely formatted way.
gistlibby LogSnag