All about Arrays in C#—Jagged Arrays


Jump to: navigation, search
Visual C# Tutorials
C# Tutorials

All about Arrays in C#

© 2006 Christian Gross

Jagged Arrays

A jagged array is an array of arrays. Unlike rectangular arrays, the sub-arrays of a jagged array can have different numbers of elements.

For example, the following code declares a two-dimensional jagged array. The array’s layout in memory is shown in Figure 14-10.

  • The length of the first dimension is 3.
  • The declaration can be read as "jagArr is an array of three arrays of ints."
  • Notice that the figure shows four array objects—one for the top-level array, and three for the sub-arrays.
// Declare and create top-level array.
int[][] jagArr = new int[3][];
 
// Declare and create sub-arrays. 
...


Image:7230f1410.jpg
Figure 14-10. A jagged array is an array of arrays.


Previous_Page_.gif Next_Page_.gif

Share this page
  • del.icio.us
  • Facebook
  • Google+
  • StumbleUpon