Q:

Write C# Program to Demonstrate Jagged Arrays

0

Write C# Program to Demonstrate Jagged Arrays

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability.

using System;
class Program
{
    static void Main()
    {
        int[][] jagArray = new int[3][];
        jagArray[0] = new int[2];
        jagArray[0][0] = 12;
        jagArray[0][1] = 13;
        jagArray[1] = new int[1] { 12 };
        jagArray[2] = new int[3] { 15, 16, 17 };
        for (int i = 0; i < jagArray.Length; i++)
        {
            int[] innerArray = jagArray[i];
            for (int a = 0; a < innerArray.Length; a++)
            {
                Console.WriteLine(innerArray[a] + " ");
            }
        }
        Console.Read();
    }
}

Result:

12

13

12

15

16

17

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write C# Program to Find Minimum and Maximum of Nu... >>
<< Write C# Program to Convert a 2D Array into 1D Arr...