Jagged With SubArrays : Jagged Arrays « Data Structure « C# / CSharp Tutorial






A jagged array is an array of arrays in which the length of each array can differ.

using System;

class MainClass
{
   static void Main()
   {
      int[][,] Arr;       
      Arr = new int[2][,];

      Arr[0] = new int[,] { { 1, 2 }, { 10, 20 } };
      Arr[1] = new int[,] { { 3, 4, 5 }, { 30, 40, 50 } };

      for (int i = 0; i < Arr.GetLength(0); i++)
      {
         for (int j = 0; j < Arr[i].GetLength(0); j++)
         {
            for (int k = 0; k < Arr[i].GetLength(1); k++)
            {
               Console.WriteLine ("[{0}][{1},{2}] = {3}", i, j, k, Arr[i][j, k]);
            }
         }
      }
   }
}
[0][0,0] = 1
[0][0,1] = 2
[0][1,0] = 10
[0][1,1] = 20
[1][0,0] = 3
[1][0,1] = 4
[1][0,2] = 5
[1][1,0] = 30
[1][1,1] = 40
[1][1,2] = 50








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