Jagged Arrays

This section describes jagged arrays which contain arrays as elements.

A Jagged array is an array that contains arrays as elements. Here are some examples:

// JaggedArrays.cs
// Copyright (c) 2006 HerongYang.com. All Rights Reserved.

using System;
class JaggedArrays {
   static void Main() {
      int[] a1 = new int[9]; // array of int
      int[,] a2 = new int[3,9]; // two dimensional array of int
      int[][] j1 = new int[9][]; // array of array of int
      int[][,] j2 = new int[9][,]; // array of two dimensional array
      int[,][] j3 = new int[3,9][]; // two dimensional array of array
      a1[5] = 5;
      a2[1,5] = 15;
      j1[0] = a1;
      j2[0] = a2;
      j3[0,0] = a1;
      Console.WriteLine("a1[5] = {0}", a1[5]);
      Console.WriteLine("a2[1,5] = {0}", a2[1,5]);
      Console.WriteLine("j1[0][5] = {0}", j1[0][5]);
      Console.WriteLine("j2[0][1,5] = {0}", j2[0][1,5]);
      Console.WriteLine("j3[0,0][5] = {0}", j3[0,0][5]);
   }
}

Output:

a1[5] = 5
a2[1,5] = 15
j1[0][5] = 5
j2[0][1,5] = 15
j3[0,0][5] = 5

Table of Contents

 About This Book

 Introduction of C# (C Sharp)

 Data Type and Variables

 Logical Expressions and Conditional Statements

 Arrays and Loop Statements

Data Type Features

 The "decimal" Data Type

 Simple Types Are "struct" Types

 Type System Unification

Jagged Arrays

 Floating-Point Data Types

 Passing Parameters to Methods

 Execution Environment Class

 Visual C# 2010 Express Edition

 Class Features

 C# Compiler and Intermediate Language

 Compiling C# Source Code Files

 MSBuild - Microsoft Build Engine

 Memory Usages of Processes

 Multithreading in C#

 Async Feature from C# 5

 System.IO.FileInfo Class

 System.Diagnostics.FileVersionInfo Class

 WPF - Windows Presentation Foundation

 Partial Classes and Partial Methods

 Archived Tutorials

 References

 Full Version in PDF/ePUB