Beheltcarrot
Beheltcarrot

Reputation: 43

Multidimensional Array (2d) of Arrays

I need to make 2d array of arrays.

int[,][] array = new int[n,m][]; 
  for (int i=0; i< m; i++)
    {
      for (int j=0; j< n; j++)
        {
          int r = ran.Next(1, 7);
          int[] arraybuf = new int[r]; 
          for (int z = 0; z < r; z++)
            {
              arraybuf[z] = 1;
            }
          array[i, j] = arraybuf;
          Console.WriteLine(array[i, j]);                                
        }
            Console.WriteLine();
   }

When i'm doing this, console shows

System.Int32[]

in every place where array must be.

Upvotes: 0

Views: 62

Answers (1)

Teodor Kurtev
Teodor Kurtev

Reputation: 1049

Because it is an array. You have an 2D array of arrays of type int.

If you want to display the contents of the array in a specific cell you could do:

   Console.WriteLine(string.Join(", ", array[i, j]));

Upvotes: 3

Related Questions