I m trying to declare a 2D dynamic array below is my code:
var marray= new[,]
{
{
"1",
"Module 1.1",
"Module 1.2",
" Module 1.3",
"Module 1.4",
"Module 1.5"
},
{
"2",
"Module 2.1"
}
};
I am getting error on second value "An array initializer of '6' is expected". I can understant it is expecting 2nd to be having 6 values but I need it to be dynamic of any length. I dont know much about array so cannot resolve it. Can you please guide. Thanks.
Sumit Kesarwani
04-Sep-2013You want a ragged array rather than a straight multi-dimensional array because your sub-array sizes are not the same.
Declare as
var marray= new[][]
rather than
var marray= new[,]