Good morning
The following code generates the exception: "Option Strict On disallows implicit conversion from System.Array to 1-dimensional array of 'String'.
I've been unable to find the conversion command that works. If any of you fine folks could point me in the right direction it would be appreciated
------------------------------------
Dim rdr As SqlDataReader = cmd.ExecuteRead e
Dim roleList As New ArrayLis
Do While rdr.Rea
roleList.Add(rd r("group_name ")
Loo
'Convert the roleList ArrayList to a String arra
' EXCEPTION GENERATED HER
Dim roleListArray As String() = roleList.ToArra y(GetType(Strin g)
Regards
Mar 4 8563
Mark,
Although ToArray returns a string array, it is boxed in a generic array. You
need to cast it to a string array. Try this:
Dim roleListArray As String() =
DirectCast(role List.ToArray(Ge tType(String)), String())
-- Alex Papadimoulis
"Petro" <ma************ *********@yahoo .com> wrote in message
news:B9******** *************** ***********@mic rosoft.com... Good morning,
The following code generates the exception: "Option Strict On disallows
implicit conversion from System.Array to 1-dimensional array of 'String'." I've been unable to find the conversion command that works. If any of you
fine folks could point me in the right direction it would be appreciated. -------------------------------------
Dim rdr As SqlDataReader = cmd.ExecuteRead er Dim roleList As New ArrayList Do While rdr.Read roleList.Add(rd r("group_name") ) Loop
'Convert the roleList ArrayList to a String array ' EXCEPTION GENERATED HERE Dim roleListArray As String() =
roleList.ToArra y(GetType(Strin g)) Regards, Mark
"Petro" <ma************ *********@yahoo .com> schrieb Good morning,
The following code generates the exception: "Option Strict On disallows implicit conversion from System.Array to 1-dimensional array of 'String'."
I've been unable to find the conversion command that works. If any of you fine folks could point me in the right direction it would be appreciated.
-------------------------------------
Dim rdr As SqlDataReader = cmd.ExecuteRead er Dim roleList As New ArrayList Do While rdr.Read roleList.Add(rd r("group_name") ) Loop
'Convert the roleList ArrayList to a String array ' EXCEPTION GENERATED HERE Dim roleListArray As String() = roleList.ToArra y(GetType(Strin g))
Dim roleListArray As String()
roleListArray = directcast( _
roleList.ToArra y(GetType(Strin g)), _
string() _
)
--
Armin
Alex
Thank you. I tried converting using many different ways but not the way that you suggested. ;-
You used DirectCast, as do many other members here, when type conversion is required. With reference to the VB Language Reference for this command, <A href="http://msdn.microsoft. com/library/default.asp?url =/library/en-us/vblr7/html/vakeydirectcast .asp" /A>, CType also works. It may be because I'm relatively new to programming that I don't quite grasp the subtilties of the difference between the two, so why choose DirectCast when it seems that CType will succeed where DirectCast will not? Is run-time performance the only advantage
Regards
Mar
Petro,
The main difference is that CType will try to convert where as DirectCast
will not. If the returned object is what you want it to be (such as in the
Array vs String() case), then use DirectCast. I suspect you'll probably
rarely use CType, as the builtin conversions (such as CInt,CStr, etc) work
the same and are easier to use. Another example:
DirectCast( 4.2, Integer) -- fail, because 4.2 is a floating point
CType(4.2, Integer) -- success, returns 4
-- Alex Papadimoulis
"Petro" <ma************ ********@yahoo. com> wrote in message
news:97******** *************** ***********@mic rosoft.com... Alex,
Thank you. I tried converting using many different ways but not the way
that you suggested. ;-) You used DirectCast, as do many other members here, when type conversion
is required. With reference to the VB Language Reference for this command,
<A
href="http://msdn.microsoft. com/library/default.asp?url =/library/en-us/vblr7
/html/vakeydirectcast .asp" /A>, CType also works. It may be because I'm
relatively new to programming that I don't quite grasp the subtilties of the
difference between the two, so why choose DirectCast when it seems that
CType will succeed where DirectCast will not? Is run-time performance the
only advantage? Regards, Mark
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Siemel Naran |
last post by:
Here is a question about implicit conversion from T (&) to ptrcarray<T>.
I wrote a class
template <class T>
struct ptrcarray
{
T * array;
size_t size;
|
by: Steve Gough |
last post by:
Could anyone please help me to understand what is happening here? The
commented line produces an error, which is what I expected given that
there is no conversion defined from type double to type Test. I
expected the same error from the following line, but it compiles fine.
The double is silently truncated to an int and then fed in to the
implicit conversion operator. Why does this happen? Is there any way
that I can keep the implicit...
|
by: Girish |
last post by:
Im trying to understand implicit type conversions from object -> string and
vice versa.
I have two classes, one Driver and one called StringWrapper. These are just
test classes that try and emulate the pattern im trying to follow in an
existing project.
These are my steps:
1) I have a method "printMe" existing in the application which originally
used to take in a string. This method is static and sits in the Driver
|
by: Aaron Queenan |
last post by:
Given the classes:
class Class
{
public static implicit operator int(Class c)
{
return 0;
}
}
class Holder
|
by: Chad Z. Hower aka Kudzu |
last post by:
I have an implicit conversion set up in an assembly from a Stream to
something else. In C#, it works. In VB it does not.
Does VB support implicit conversions? And if so any idea why it would work in
a C# program but not VB?
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
| |
by: thav |
last post by:
I'm taking an intro class right now , I'm not having any fun so far. I keep getting implicit conversion. I tried everything from .toString and declaring the array as a string which gives me problems later down when using a foreach statement later on. Can anyone point me in the right direction?
I created an Array.
Contact Contacts = new Contact;
and I am getting string input from users, using the Console.ReadLine.
Then I created an...
|
by: drop |
last post by:
Hi all,
I'd like to know if it's possible to declare an implicit type
conversion for when I use declarative Synthax in html.
For example, when I have the DropDownList, I can declatively set it's
Selected value like this : SelectedValue='<%# Bind("TaxCondition")
%>'. In this case, TaxCondition is an int, and the conversion from int
to string and string to int is made automatically.
|
by: jonpb |
last post by:
Hi, Is it possible to define a implicit operator from base to derived
types in C#?
I have a Point class and would like to derive a Vector class from it and
add a couple new vector related functions, like Normalize(). The problem
is Vector cannot use any of the Point operator overloads with a compile
time error that there is no implicit conversion from Point to Vector. I
tried adding an implicit operator to Vector:
public static implicit...
|
by: johanatan |
last post by:
Does anyone know the reasons for the lack of an implicit casting
operator in any greater depth than:
A. Automatic conversion is believed to be too error prone.
(from the FAQ at the bottom of: http://www.boost.org/libs/smart_ptr/shared_ptr.htm)
Can anyone say specifically what about the implicit conversion would
be dangerous? I can think of a few things that would require care
about usage of smart pointers with implicit conversions,...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |