Re: Arghhh...strict, but not strict enough
- From: "Scott M." <s-mar@xxxxxxxxxxxxx>
- Date: Sun, 12 Apr 2009 10:50:40 -0400
CType is not short for "convert" to a type. It's short for "cast" to type.
IMHO the term "convert" is thrown around too easily. Convert implies that a
thing is transformed into a different thing. like a person can convert their
religion, they may do that, but they remain the same person.
That's not what happens with CType. With CType, you may get a duplication
of the original data, but with a different type of reference variable
pointing to that new data.
I just think that the term "convert" is used (even by Microsoft)
incorrectly. It gives the impression that something other that what is
actually happening is taking place.
-Scott
"Cor Ligthert[MVP]" <Notmyfirstname@xxxxxxxxx> wrote in message
news:Ooaq29vuJHA.4476@xxxxxxxxxxxxxxxxxxxxxxx
Scott,
I see therefore CType is a shortcut for Convert Type. That is because it
does not convert, that is simple American logic.
They make it so difficult there in America for people outside the USA.
Although this page state something else, can it be that CType is to
convert and cast as that is possible instead.
http://msdn.microsoft.com/en-us/library/kca3w8x6.aspx
Cor
"Scott M." <s-mar@xxxxxxxxxxxxx> wrote in message
news:uVmvb7suJHA.4592@xxxxxxxxxxxxxxxxxxxxxxx
Not quite Armin, You don't get a conversion with CType. You may get a
duplication of data boxed or unboxed into a new type if your input and
output parametes are reference and value types or vice versa. When both
of the inputs are of the same fundamental type, you just get a cast of
the reference.
A conversion implies that the original data is transformed into something
else and CType doesn't do that. It *can* copy data and put that into a
new type, but it can't convert the data into a new type.
-Scott
"Armin Zingler" <az.nospam@xxxxxxxxxx> wrote in message
news:el6hWBduJHA.5764@xxxxxxxxxxxxxxxxxxxxxxx
John Whitworth wrote:
Thanks Armin - I got there from Patrice's message. But is there a
difference between CType and directcast?
DirectCast only casts. CType (also) converts if necessary. Even if both
lead
to the same (IL) code in this case, I prefer Directcast - personal taste
only - if I want to cast. With CType, the VB compiler generates the code
required to do the conversion in other cases.
The difference between casting and converting is that a conversion
creates a new object while casting just changes the type of the
reference.
Armin
.
- Follow-Ups:
- Re: Arghhh...strict, but not strict enough
- From: J.B. Moreno
- Re: Arghhh...strict, but not strict enough
- From: Armin Zingler
- Re: Arghhh...strict, but not strict enough
- From: Cor Ligthert[MVP]
- Re: Arghhh...strict, but not strict enough
- References:
- Arghhh...strict, but not strict enough
- From: John Whitworth
- Re: Arghhh...strict, but not strict enough
- From: Armin Zingler
- Re: Arghhh...strict, but not strict enough
- From: John Whitworth
- Re: Arghhh...strict, but not strict enough
- From: Armin Zingler
- Re: Arghhh...strict, but not strict enough
- From: Scott M.
- Re: Arghhh...strict, but not strict enough
- From: Cor Ligthert[MVP]
- Arghhh...strict, but not strict enough
- Prev by Date: Re: Arghhh...strict, but not strict enough
- Next by Date: Re: Arghhh...strict, but not strict enough
- Previous by thread: Re: Arghhh...strict, but not strict enough
- Next by thread: Re: Arghhh...strict, but not strict enough
- Index(es):
Relevant Pages
|