Jagged Arrays in C#

Definitions

Arrays which have more than one dimension; these arrays-of-arrays are called multidimensional arrays. They are very similar to standard arrays with the exception that they have multiple sets of square brackets after the array variable.

step

  1. Go to Solution explorer and open console project.
  2. Add new class.
    1. using System;  
    2. public class JaggedArray  
    3. {  
    4.     static void Main()  
    5.     {  
    6.         int[][] jaggedArr = new int[][]   
    7.         {  
    8.             new int[]   
    9.                 {  
    10.                     1,2  
    11.                 },  
    12.                 new int[]  
    13.                 {  
    14.                     1,2,3  
    15.                      
    16.                 },  
    17.                 new int[]   
    18.                 {  
    19.                     1,2,3,4  
    20.                       
    21.                 }  
    22.         };  
    23.         foreach(int[] array in jaggedArr)  
    24.         {  
    25.             foreach(int e in array)  
    26.             {  
    27.                 Console.Write(e + " ");  
    28.             }  
    29.         }  
    30.         Console.Write('\n');  
    31.     }  
    32. }  
    33. Console.WriteLine(array[0, 1]);  
    34. Console.WriteLine(array[1, 0]);  
    35. Console.WriteLine(array[1, 1]);  
    36. Console.ReadLine();  
    37. }  
    38. }  
Up Next
Ebook Download
View all
Learn
View all