I want to create a dynamic jagged array with dynamic data. The problem is that a part of the jagged array is only a two column type and the rest of it is a 4 column type. Code is in C#.
public static Object[][] my_array = new Object[20][];
public static void LoadData()
{
for(int i = 0; i < 20; i++)
{
my_array[i] = new Object[20];
my_array[i][0] = "Data1";
my_array[i][1] = "Data2";
my_array[i][2] = "Data3";
my_array[i][3] = "Data4";
my_array[i][4] = new Object[100];
for(int j = 0; j < 100; j++)
{
my_array[i][4][j] = new Object[200];
my_array[i][4][j][0] = "SubData1";
}
my_array[i][5] = "Data6";
}
}
I get following error:
Severity Code Description Project File Line Suppression State Error CS0021 Cannot apply indexing with [] to an expression of type 'object'
Is this even possible to do this in C#?
List<T>structures, they will give you dynamic flexibility. If you have elements of different types, then maybe you should use a class with typed and named members.my_array[i][4]is anObject[]instance, you have to cast itmy_array[i][j]is astringand sometimes there is anotherobject[]. Do you want to parse some kind of JSON or XML? Because there are parsers for that.