Originally posted by MrPolite
I dont know why I always have trouble workign with array lists. I want to convert an array list to an array of strings. I tried this but I get an error:
string[] result=(string[])arrConvos.ToArray (typeof(string[]))

the error is: "At least one element in the source array could not be cast down to the destination array type."


this works well, but shouldnt there be another way for this? why doesnt the above code work?
Code:
    result= new string[arrConvos.Count-1];
    for (int i=0; i<result.Length; i++)
        result[i] = arrConvos[i].ToString();
I think it is because you are putting an item in the arraylist that isn't a string. But when you do that second piece of code, you are taking that item and calling it's ToString() method which will convert it to a string and make it work.

Inspect your arraylist in the debug window. Foreach through it and do a debug.writeline on it to see if any type held in the arraylist is not of type string.