Hi guys, I have this problem. I’m trying to make a multidimensional array like this:
var myArray = new Array();
myArray[0] = new Array("Pera", "Manzana", "Naranja");
myArray[1] = new Array("Rojo", "Azul", "Amarillo");
myArray[2] = new Array("Verde", "Morado", "Marrón");
Debug.Log(myArray[1][2]); //should by "Amarillo" but get this " Type 'Object' does not support slicing."
I get the mistake that Object does’t support slicing!! And I don’t know how to show the correct value. Thank you so much.
First solution, do not use Array, they are prone to error a they are not strongly type and then they make it all slow as you need casting everywhere.
The solution is to use jagged arrays or “jagged list” maybe in your case. You could also think of 2D array. The choice will depend on how much you know at start.
Here is an example:
var myList = new List<string[]>();
myList.Add(new string[]{"Pedro", "Diego"});
myList.Add(new string[]{"Jesus", "Juan", "Fernando"});
Here you are kinda free but you would have to check for the length of the array to avoid getting out of it.
It is strongly typed as only string array as accepted and you can add arrays of any sizes.