O'Reilly logo

C# Data Structures and Algorithms by Marcin Jamro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Multi-dimensional arrays

The arrays in the C# language do not need to have only one dimension. It is also possible to create two-dimensional or even three-dimensional arrays. To start with, let's take a look at an example regarding the declaration and initialization of a two-dimensional array with 5 rows and 2 columns:

int[,] numbers = new int[5, 2]; 

If you want to create a three-dimensional array, the following code can be used:

int[, ,] numbers = new int[5, 4, 3]; 

Of course, you can also combine a declaration with an initialization, as shown in the following example:

int[,] numbers = new int[,] = 
{ 
    { 9, 5, -9 }, 
    { -11, 4, 0 }, 
    { 6, 115, 3 }, 
    { -12, -9, 71 }, 
    { 1, -6, -1 } 
};

Some small explanation is necessary for the way you access particular ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required