Converting ArrayList to String Array

W

Walter Zydhek

Is it possible to convert an ArrayList to a string array?

I have a routine that takes a string array as a parameter,
converts it to an ArrayList for manipulation purposes,
and now I need to convert it back to a string array.

example of code I am using:

Sub MakeChanges(byval strChange() as string) as string()
Dim aryValue As ArrayList = New ArrayList(strChange)
aryValue.add "newvalue"

' here I want to convert the aryValue back to a string()
End Sub

-Walt Zydhek
 
J

Jon Skeet [C# MVP]

Walter Zydhek said:
Is it possible to convert an ArrayList to a string array?

I have a routine that takes a string array as a parameter,
converts it to an ArrayList for manipulation purposes,
and now I need to convert it back to a string array.

example of code I am using:

Sub MakeChanges(byval strChange() as string) as string()
Dim aryValue As ArrayList = New ArrayList(strChange)
aryValue.add "newvalue"

' here I want to convert the aryValue back to a string()
End Sub

Yes - look at ArrayList.ToArray (Type). You'll need to cast the
reference returned to a string array.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top