Re: Arghhh...strict, but not strict enough
- From: "Scott M." <s-mar@xxxxxxxxxxxxx>
- Date: Sat, 11 Apr 2009 13:56:36 -0400
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: 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
- 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
|
Loading