All about Arrays in C#—Comparing Rectangular and Jagged Arrays


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

All about Arrays in C#

© 2006 Christian Gross

Comparing Rectangular and Jagged Arrays

The structure of rectangular and jagged arrays is significantly different. For example, Figure 14-14 shows the structure of a rectangular three-by-three array, and a jagged array of three one-dimensional arrays of length 3.

  • Both arrays hold nine integers, but as you can see, their structures are quite different.
  • The rectangular array has a single array object, while the jagged array has four array objects.


Image:7230f1414.jpg
Figure 14-14. Comparing the structure of rectangular and jagged arrays


One-dimensional arrays have specific instructions in the CIL that allow them to be optimized for performance. Rectangular arrays do not have these instructions, and are not optimized to the same level. Because of this, it can sometimes be more efficient to use jagged arrays of one-dimensional arrays—which can be optimized—than rectangular arrays, which cannot.

On the other hand, the programming complexity can be less for a rectangular array because it can be treated as a single unit, rather than an array of arrays.


Previous_Page_.gif Next_Page_.gif

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