jagged array example

Category > CSHARP || Published on : Monday, March 1, 2021 || Views: 328 || jagged array example c#


Here Pawan Kumar will explain how to jagged array example

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

namespace ConsoleApp1
{
    class Program
    {
        // jagged array example
        static void Main(string[] args)
        {
            String[][] jaggedArray = new String[3][];

            jaggedArray[0] = new string[1];
            jaggedArray[1] = new string[3];
            jaggedArray[2] = new string[2];

            jaggedArray[0][0] = "test1";
      
            jaggedArray[1][0] = "q1";
            jaggedArray[1][1] = "q2";
            jaggedArray[1][2] = "q3";

            jaggedArray[2][0] = "e1";
            jaggedArray[2][1] = "e2";

            for (int i = 0; i < jaggedArray.Length; i++)
            {
                string[] innerArray= jaggedArray[i];
                for (int j = 0; j < innerArray.Length; j++)
                {
                    Console.WriteLine(innerArray[j]);
                }
            }
            Console.ReadLine();
        }
    }
}