-2

I did my research on the web but I couldn't find any advice how to dynamically create multidimensional (rank >1) array (it could be a jagged array).

In other words program will ask about number of dimensions (rank) first, then about number of elements per dimension (rank) and then it will create the array.

Is it possible?

user1146081
  • 195
  • 15

1 Answers1

0

multidimensional no, but no problem with jagged - here is a simple example:

using System;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {

        List<List<List<int>>> myJaggedIntList = new List<List<List<int>>>();

        myJaggedIntList.Add(new List<List<int>>());
        myJaggedIntList[0].Add(new List<int>());
        myJaggedIntList[0][0].Add(3);

        Console.WriteLine(myJaggedIntList[0][0][0].ToString());
    }
}

each item in the first List is a List, each item in the second List is also a List, and each item in the third List is an int. what's the problem with that?

Play with it yourself in this fiddle.

Zohar Peled
  • 79,642
  • 10
  • 69
  • 121