use ToArray function in ArrrayList

  • Thread starter Thread starter Grey
  • Start date Start date
G

Grey

Dear all

I want to know that how to use ToArray function in ArrayList. I have an ArrayList which is storing string, Actually, I want to use the Join method, so I think I need to convert the arraylist to array first. The question is do I need to convert the arraylist to array in order to use the Join method? If so, please advise how to convert??

Million Thanks
 
Hi Grey,

Something like this:

string[] myStrings = myArrayList.ToArray(typeof(string));

string allStrings = String.Join(",", myStrings);

Joe
--
http://www.csharp-station.com
Dear all

I want to know that how to use ToArray function in ArrayList. I have an ArrayList which is storing string, Actually, I want to use the Join method, so I think I need to convert the arraylist to array first. The question is do I need to convert the arraylist to array in order to use the Join method? If so, please advise how to convert??

Million Thanks
 
Joe Mayo said:
Something like this:

string[] myStrings = myArrayList.ToArray(typeof(string));

Slight error here - ArrayList.ToArray is declared to return Array, so
you need to cast:

string[] myStrings = (string[]) myArrayList.ToArray(typeof(string));
 
Back
Top