Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# jagged array initialization

// In C#, a jagged array consists of multiple arrays as its element
//Syntax: 
//dataType[ ][ ] nameOfArray = new dataType[rows][ ];


using System;

namespace JaggedArray {
  class Program {
    static void Main(string[] args) {

     // create a jagged array
     int[ ][ ] jaggedArray = {
         new int[] {1, 3, 5},
         new int[] {2, 4},
      };

     // print elements of jagged array
     Console.WriteLine("jaggedArray[1][0]: " + jaggedArray[1][0]);
     Console.WriteLine("jaggedArray[1][1]: " + jaggedArray[1][1]);

     Console.WriteLine("jaggedArray[0][2]: " + jaggedArray[0][2]);

     Console.ReadLine();
    }    
  }
}
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #jagged #array #initialization
ADD COMMENT
Topic
Name
2+1 =