Multidimensional jagged arrays : Jagged Arrays « Data Structure « C# / CSharp Tutorial






using System;

class MainClass
{
    public static void Main()
    {
        int[][] matrix = {new int[5], new int[4], new int[2] };
        matrix[0][3] = 4;
        matrix[1][1] = 8;
        matrix[2][0] = 5;
        
        for (int i = 0; i < matrix.Length; i++)
        {
            for (int j = 0; j < matrix[i].Length; j++)
            {
                Console.WriteLine("matrix[{0}, {1}] = {2}", i, j, matrix[i][j]);
            }
        }    
    }
}
matrix[0, 0] = 0
matrix[0, 1] = 0
matrix[0, 2] = 0
matrix[0, 3] = 4
matrix[0, 4] = 0
matrix[1, 0] = 0
matrix[1, 1] = 8
matrix[1, 2] = 0
matrix[1, 3] = 0
matrix[2, 0] = 5
matrix[2, 1] = 0








11.7.Jagged Arrays
11.7.1.Jagged With SubArrays
11.7.2.Use foreach statement to loop through jagged array
11.7.3.Demonstrate jagged arrays
11.7.4.Demonstrate Length with jagged arrays.
11.7.5.Multidimensional jagged arrays