using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CSharp2DArrayDemo { class Program { public void Run() { //Declare two-dimensional array that can hold integers int[][] intArray; //Initialize and integer int intValue = 0; // Initialize A string variable to hold a row of numbers converted to strings string numberRow = " "; //Initialise multi-dimensional array with 10 elements. More precisely, 10 ROWS intArray = new int[10][]; //Initialise the second dimension of the array with 10 elements //within each element of the first array //LOOP Over each row and initialize 10 COLUMNS for (int i = 0; i < intArray.Length; i++) { intArray[i] = new int[10]; } // Populate the int multi-dimensional array using a nested for loop: // - First Loop is to loop over each ROW // - Second loop is to loop over each column for that row for (int j = 0; j < intArray.Length; j++) { for (int k = 0; k < intArray.Length; k++) { // The intValue variable will count from 1 to a 100 // each of these numbers will be stored in each member // of the multi-dimensional array intValue++; intArray[j][k] = intValue; if (intValue < 10) { // Convert each number to a string and append it to the // string variable numberRow += Convert.ToString(intArray[j][k]) + " "; } else { //Append the number to the string // The number will be automatically converted to a string numberRow += intArray[j][k] + " "; } } // Print out the row of numbers Console.WriteLine(numberRow); numberRow = " "; } } static void Main(string[] args) { Program t = new Program(); t.Run(); Console.ReadLine(); } } }