Your example does not compile. I took the liberty of changing the first 2 lines so that it would.
You can access specific arrays within the ArrayList
by index, casting them as the array type that they are. Then, you can access individual elements by index.
The below example gets the string "Alex" from stringArray
:
int[] intArray = new int[3];
string[] stringArray = new string[3];
stringArray[0] = "Bob";
stringArray[1] = "John";
stringArray[2] = "Alex";
intArray[0] = 5;
intArray[1] = 7;
intArray[2] = 13;
ArrayList listOfArrays = new ArrayList() { intArray, stringArray };
// Get the string[] by index from the ArrayList:
string[] nestedStringArray = (string[])listOfArrays[1];
// Access an element:
string alex = nestedStringArray[2];
// Or do the above 2 lines in a single line:
alex = ((string[])listOfArrays[1])[2];
If you are just exploring the language, then this should help. However, this is not likely to be a good solution to use in a real application. Storing a variety of types in a single object and then casting in order to access them is a recipe for major headaches.