C# - Multidimensional int arrays

c#, multidimensional-array

Solution

I believe the term you're looking for is a jagged array.

It can be done like this:

int[][] jaggedArray2 = new int[][] 
{
    new int[] {1,3,5,7,9},
    new int[] {0,2,4,6},
    new int[] {11,22}
};

And you can iterate through them like this:

for(int i = 0; i < jaggedArray2.Length; i++)
    for(int j = 0; j < jaggedArray2[i].Length; j++)
    {
        //do something here.
    }

Problem

How do you declare a "deep" array in C#? I would like to have a int array like: [ 1, 4, 5, 6, [3, 5, 6, 7, 9], 1, 4, 234, 2, 1,2,4,6,67, [1,2,4,44,56,7] ] I've done this before, but can't remember the right syntax. But it was something a like what is written below: Int32[] MyDeepArray = new Int32[] = {3, 2, 1, 5, {1, 3, 4, 5}, 1, 4, 5}; And how do I iterate it correctly.. How do I check that an array is an array? Thanks!

Original source