By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

cast arraylist to string array

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
JMW
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.

"Peter" wrote:
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

Nov 20 '05 #2

P: n/a
String sa(al.count-1)

dim sa(al.count-1) as string
Nov 20 '05 #3

P: n/a

"JMW" <JM*@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
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.

"Peter" wrote:
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


Better still,

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

Nick Hall
Nov 20 '05 #4

P: n/a
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))
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.