CType

T

Todd Plambeck

Is there a more C# like alternative to CType? I don't like using the
VB6esque "C" conversion methods(CStr, CInt, etc) . I'd prefer to user
something like Convert.ToInt32(), but can't find a equivalent for converting
objects.

Thanks,

Todd
 
C

Cor Ligthert [MVP]

Todd,

I don't know why you want to use all posibilities you get. However you can
use in VBNet any System.Net methods as you use in C# as long as it is not
C# unsave code.

(The same as you can use in C# every Microsoft.VisualBasic namespace method
in C#)

Therefore Convert.ToInt32 is the same in Visual Basic in Net as it is in C#.

If you don't want to use CInt that is your choise, if you like to type more
characters I won't keep you from doing that. I just type Cint as it is a
valid Net method. (Not a system.net namespace method by the way, however an
other official namespace from Net)

:)

I hope this helps,

Cor
 
H

Herfried K. Wagner [MVP]

Todd Plambeck said:
Is there a more C# like alternative to CType? I don't like using the
VB6esque "C" conversion methods(CStr, CInt, etc) . I'd prefer to user
something like Convert.ToInt32(), but can't find a equivalent for
converting objects.

If you are looking for cast operators, 'DirectCast' and 'CType' are the way
to go. There is absolutely no reason for not using the 'C*'
conversions/casts.
 
T

Todd Plambeck

Thanks guys! CType it is. I have read that Convert.To... is more
efficient/faster then the C* methods. I know, I know the fractions of
milliseconds won't make much difference, but you gotta get it anywhere you
can.

Thanks again.

Todd
 
J

Jay B. Harlow [MVP - Outlook]

Todd,
I've read the opposite that the C* methods are more efficient/faster then
the Convert.To* methods.

http://www.panopticoncentral.net/archive/2004/06/07/1200.aspx


Hope this helps
Jay


| Thanks guys! CType it is. I have read that Convert.To... is more
| efficient/faster then the C* methods. I know, I know the fractions of
| milliseconds won't make much difference, but you gotta get it anywhere you
| can.
|
| Thanks again.
|
| Todd
|
| | >> Is there a more C# like alternative to CType? I don't like using the
| >> VB6esque "C" conversion methods(CStr, CInt, etc) . I'd prefer to user
| >> something like Convert.ToInt32(), but can't find a equivalent for
| >> converting objects.
| >
| > If you are looking for cast operators, 'DirectCast' and 'CType' are the
| > way to go. There is absolutely no reason for not using the 'C*'
| > conversions/casts.
| >
| > --
| > M S Herfried K. Wagner
| > M V P <URL:http://dotnet.mvps.org/>
| > V B <URL:http://classicvb.org/petition/>
|
|
 

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