cast arraylist to string array

P

Peter

I get an error when I try to do this:

dim al as new arraylist
al.add("Value1")
al.add("Value2")
al.add("Value2")

dim sa(al.count) as string

sa = al



I can use a loop statement to fill the array but there must be an easier way.

Also, is there any way to write this information to a textbox like a string array.

IE. textbox.text = sa 'works great
but.... textbox.text = al 'generates an error

Thanks
 
G

Guest

try this...

dim al as new arraylist
al.add("Value1")
al.add("Value2")
al.add("Value3")

String sa(al.count-1)
al.copyto(sa)

jason.
 
N

Nick Hall

JMW said:
try this...

dim al as new arraylist
al.add("Value1")
al.add("Value2")
al.add("Value3")

String sa(al.count-1)
al.copyto(sa)

jason.

Better still,

Dim sa() as String = DirectCast(al.ToArray(GetType(String)), String())

Nick Hall
 
J

Jared

Try this:

Dim al As New ArrayList
al.Add("Value1")
al.Add("Value2")
al.Add("Value2")
Dim sa() As String = al.ToArray(GetType(System.String))
 

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