I need to create a list (array or any type) that would hold values, but these values would vary in size. I'm not sure what data type to use in C#. In PHP it would be something like this;
$a = [1,2];
$a[] = 3;
$a[][] = [4,5,6]; // This would hold any number of values
$a[] = 7;
$a[][] = [8,9]; // This would hold any number of values
The result would be an 'array' that could hold any number of values like this: See how index 3 is also an array that could hold any number of values. The same is for index 5.
> Array (
> [0] => 1
> [1] => 2
> [2] => 3
> [3] => Array
> (
> [0] => Array
> (
> [0] => 4
> [1] => 5
> [2] => 6
> )
>
> )
>
> [4] => 7
> [5] => Array
> (
> [0] => Array
> (
> [0] => 8
> [1] => 9
> )
>
> )
>
> )
I tried this way, but it doesn't work:
int[,] array2D = new int[,] { { 1, 2 }, { 3 }, { 4, 5, 6 }, { 7, 8 } };
List<object>
but you're going to have a hard time doing anything useful with the structure unless all you want to do is serialize it.List<object>
is a poor choice to represent data. If you told us what these numbers represent and where they are coming from we may be able to make a better suggestion.int[][]
/