using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MultiDimension_Foreach
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] matrix = 
                        { 
                        {1, 2, 3, 4}, // row 0 values 
                        {5, 6, 7, 8}, // row 1 value 
                        };
            // Print the matrix on the console 
            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    Console.Write(matrix[row, col]);
                }
                Console.WriteLine();
            }

            foreach (int elt in matrix)
            {
                Console.Write(elt);
            }

            Console.WriteLine();

            int[][] myArray = new int[3][];
            myArray[0] = new int[3]{1,2,3};
            myArray[1] = new int[5] { 4,5,6,7,8};
            myArray[2] = new int[4] {9,10,11,12 };

            // sol1
            foreach (int[] row in myArray)
            {
                foreach (int elt in row)
                {
                    Console.Write(elt);
                }
                Console.WriteLine();
            }

            // sol2
            for (int row = 0; row < myArray.GetLength(0); row++)
            {
                for (int col = 0; col < myArray[row].Length; col++)
                {
                    Console.Write(myArray[row][col]);
                }
                Console.WriteLine();
            }

            Console.ReadKey();


        }
    }
}
