cast arraylist to string array

  • Thread starter Thread starter Peter
  • Start date Start date
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
 
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.
 
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
 
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))
 
Back
Top