473,385 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

cast arraylist to string array

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
4 18793
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
String sa(al.count-1)

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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Walter Zydhek | last post by:
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...
8
by: Jeff Johnson | last post by:
Hi, I've begun converting an ASP site over to .NET and I'm a novice at both the new platform as well as C#. I have a COM+ object that returns a string array when it is called. The size of...
4
by: Hrvoje Voda | last post by:
How to get a list of names from database into string array? variable name should be string array... This is the code I use... public string GetFunctionName(Guid UserID) {
5
by: Paulers | last post by:
Hello all, I have a string array with duplicate elements. I need to create a new string array containing only the unique elements. Is there an easy way to do this? I have tried looping through...
2
by: Earl | last post by:
I'm trying to do a cast and I'm not sure where I'm going wrong here. I load up the ColorExtIntID column (int) into a list array (no problem there). For binding to a 3rd party component, it has to...
1
by: dotnetnoob | last post by:
i have a arraylist that store String() array the string array hold value 1 2 4 i want to access the string array that is inside the arraylist one arraylist item at the time i search up and...
14
by: budy_ludy | last post by:
Hi All, I am new to vb .net, I have an ArrayList and i store class objects in it, and later i want to retrieve each ArrayList items and type cast to the class, How can it be done ? I used...
15
by: =?Utf-8?B?cm9nZXJfMjc=?= | last post by:
hey, I have a datatable here, but I need to make it into a string array. how do I do that?
8
by: Pim75 | last post by:
Hello, I'm defining a string array like: Dim strArray() As String = {"1", "2"} Can I add some values to this string array later in the code? It's not clear to me how to do this. I hope...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.