Getting the System.Type for String

N

Nathan Sokalski

I have the following code:

Dim values As New ArrayList()
values.Add("Yes")
values.Add("No")
values.Add("Maybe")
values.Add("Whatever")
dim x as String()=values.ToArray()

However, I recieve an error saying an Object array cannot be implicitly
converted to a String array. I noticed, however, that there is an overload
of the ToArray() method that accepts a System.Type to convert the resulting
array to. However, I am having trouble getting the System.Type for String.
Can someone help me here? Thanks.
 
N

Nathan Sokalski

Thanks, that worked great! I actually did use your suggestion of List(Of
String), I guess I just didn't think of that before since my boss gives me
such boring projects I'm a little out of practice with some of the classes I
used when I had all the free time I used to. Thanks again.
 
P

Phill W.

Nathan said:
Dim values As New ArrayList()
values.Add("Yes")
values.Add("No")
values.Add("Maybe")
values.Add("Whatever")
dim x as String()=values.ToArray()

However, I recieve an error saying an Object array cannot be implicitly
converted to a String array.

ArrayLists hold Objects (i.e. anything) but an array of Strings can only
contain Strings, hence your conversion error.

Are you still using VB'2003?
If /not/ have a play with Generics:

Dim values as New List(Of String)
values.Add("Yes")
values.Add("No")
values.Add("Maybe")
values.Add("Whatever")
Dim x as String() = values.ToArray()

HTH,
Phill W.
 

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