c# string[][] to Arraylist problems

Hi folks!

i want to convert a multidimensional array "string[][] theArray" into an ArrayList and then read out one of the partial arrays "string[] theStringArray".

the problem is that i get the error that i want to convert an object into a string[].

my code is

void myFunction(int cnt)
    ArrayList tmpList = ArrayToArrayList(theArray);
    int counter = cnt/2;

    while (counter-- >= 1)
        int lengthOfList = tmpList.Count;
        int rndM = Random.Range(0,  lengthOfList - 1);
        string[] tmpPair = tmpList[rndM];   // <--- HERE I GET THE ERROR !!!

ArrayList ArrayToArrayList(string[][] theArray)
    ArrayList theList = new ArrayList();
    for (int i = 0; i < theArray.Length; i++){
        string[] tmp = theArray*;*
 *return theList;*
*<p>so whats my problem (besides that I am new to c#)?*

You need to be casting to string[] when you grab something from the arraylist:

string[] tmpPair = (string[])tmpList[rndM];

Ideally you'd modify the code to use List instead though, that way the code should be cleaner and you won't need to cast everywhere

List<string[]> tmpList = ArrayToList(theArray);
string[] tmpPair = tmpList[rndM]; //will just work

List<string[]> ArrayToList(string[][] theArray)
    List<string[]> theList = new List<string[]>();
    //rest is the same

You'll need to have

using System.Collections.Generic;

at the top for that to work