I have the following code:
Dim values As New ArrayList()
values.Add("Yes ")
values.Add("No" )
values.Add("May be")
values.Add("Wha tever")
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.
--
Nathan Sokalski nj********@hotm ail.com http://www.nathansokalski.com/ 3 1397
Nathan Sokalski wrote:
I have the following code:
Dim values As New ArrayList()
values.Add("Yes ")
values.Add("No" )
values.Add("May be")
values.Add("Wha tever")
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.
I think you need
GetType(String)
You will still need a type conversion as well, so you end up with
Dim x As String() = CType(values.To Array(GetType(S tring)), String())
I would have just used
Dim values As New List(Of String)
' ....
Dim x As String() = values.ToArray( )
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.
--
Nathan Sokalski nj********@hotm ail.com http://www.nathansokalski.com/
"Steve Gerrard" <my********@com cast.netwrote in message
news:Br******** *************** *******@comcast .com...
Nathan Sokalski wrote:
>I have the following code:
Dim values As New ArrayList() values.Add("Ye s") values.Add("No ") values.Add("Ma ybe") values.Add("Wh atever") 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.
I think you need
GetType(String)
You will still need a type conversion as well, so you end up with
Dim x As String() = CType(values.To Array(GetType(S tring)), String())
I would have just used
Dim values As New List(Of String)
' ....
Dim x As String() = values.ToArray( )
Nathan Sokalski wrote:
Dim values As New ArrayList()
values.Add("Yes ")
values.Add("No" )
values.Add("May be")
values.Add("Wha tever")
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("May be")
values.Add("Wha tever")
Dim x as String() = values.ToArray( )
HTH,
Phill W. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Asaf Ganot |
last post by:
Hi,
I'm looking for a way to retrieve the date type of a registry value using
c#.
Since I couldn't find a way to do it with 'Microsoft.Win32', I tried to use
the good old API call 'RegEnumValue' which gives you the data type as well
as other things...
After many tries, I managed to call the function without any errors.
However, I get the data type, but not the value's name! (I even get the name
length, but the string that supose to...
|
by: Hitesh |
last post by:
Hi,
I am getting the response from another Website by using the HttpHandler in
my current site. I am getting the page but all the images on that page are
not appearing only placeholder are displayed.
Can anybody know this issue and help me to resolve this.
In past i received the response saying that i should download the image
first and then parse the actual response and modify the src attribute of the
|
by: Erol |
last post by:
How do I get a type from a string? I'm retrieving a string value from my
database so that I can set my property values dynamically. In the event
"Form1_Load", you will see that I'm trying to set the button's anchor
property to "System.Windows.Forms.AnchorStyles.Bottom" dynamically from a
string (which I commented out). How can I get this code to work. I also
started to use the variable "fi", but I don't know how to put it to good use....
|
by: Danny Gagne |
last post by:
I'm currently working an .net application (I can use 1.1 or 2.0 if needed)
that needs to read a wsdl file and generate another piece of code that can
use it. I'm encountering a problem where I cannot extract all of the type
information from the wsdl using any standard tools. I'm using HttpGet style
webservices if that makes any difference, but I want to be able to use any
type.
1. I've tried the ServiceDescription.Types and I cannot...
|
by: AshishMishra16 |
last post by:
HI friends,
I am using the Flex to upload files to server. I m getting all the details about the file, but I m not able to upload it to Server. Here is the code i m using for both flex & for Struts:
import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
| |
by: buntyindia |
last post by:
Hi,
I have a very strange problem with my application.
I have developed it using Struts.
I have a TextBox With Some fixed value in it and on Submit iam passing it to another page.
<html:form action="/login">
<html:text property="userName" value="Bunty"/>
<html:submit/>
|
by: jehugaleahsa |
last post by:
Hello:
Say I were to query the schema tables from a database management
system. Say I got a DataType field that held the string 'VARCHAR2'.
Now, I know that VARCHAR2 associates to System.String. However,
different DBMSs have different types and worse, even some with the
same type turn out to be different .NET types.
I would like DMBS-independent way of getting a .NET type from a
DataType string. Now, I have existing code that gets the...
|
by: TG |
last post by:
Hi!
Once again I have hit a brick wall here. I have a combobox in which
the user types the server name and then clicks on button 'CONNECT' to
populate the next combobox which contains all the databases in that
server. Then after the user selects a database, I have another button
that he/she click and I want to retrieve file groups from a specific
table. At this point when he/she clicks on that button I get an
error:
|
by: raghuvendra |
last post by:
Hi
I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button.
All these are aligned in a row. And Each Category Name has its corresponding Category order, Input field and a submit button.
The Category name is being fetched from the oracle db along with the corresponding Category order.
In the corresponding input field (text box) the user enters a new category order which gets stored in...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |