Check Page Rank of your Web site pages instantly:

Jagged Array Description With Code Example

 A jagged array can be defined as an arrays. The length of individual arrays of a jagged array need not be the same. Jagged arrays can be used to create tables having rows of different lengths.

A jagged array is declared using square brackets([])that indicate a single dimension.

 Example 4:

 using System;
 class Sports
 {
    
         static void Main(string[] args)
         {

                string[] atheleteNames = new string[] { "Alton White","Mary Cruz","Susan Dias" };
                string[][] events = new string[3][];
                events[0] = new string[] { "100 Mts Sprint", "200 Mts Sprint", "High Jump", "Relay" };
                events[1] = new string[] { "Tripple Jump", "Hurdles", "Long Jump" };
                events[2] = new string[] { "200 Mts Sprint", "High Jump" };
                Console.WriteLine("Participants\tEvents");
                for (int i = 0; i < events.GetLength(0); i++)
                {

                     Console.Write("{0} \t",atheleteNames[i]);
                     for (int j = 0; j < events[i].GetLength(0); j++)
                     {

                          Console.Write("[{0}] ",events[i][j]);
                       
                     }
                     Console.WriteLine();
                }

          }
 }

0 comments:

Post a Comment