Why use anything besides Ctype to convert datatypes?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello
Everything in .Net is an object and CTYPE converts one datatype to another
datatype so why use Cstr, Cint or any other method to convert from one
datatype to another?
 
winlin said:
Hello
Everything in .Net is an object and CTYPE converts one datatype to
another datatype so why use Cstr, Cint or any other method to
convert from one datatype to another?

Because it's shorter. "CInt(s)" is shorter than "CType(s, Integer)"


Armin
 
Hello
Everything in .Net is an object and CTYPE converts one datatype to another
datatype so why use Cstr, Cint or any other method to convert from one
datatype to another?

For backwards compatibility or for those who prefer to write in vb6 style.

-h-
 
winlin said:
Hello
Everything in .Net is an object and CTYPE converts one datatype to another
datatype so why use Cstr, Cint or any other method to convert from one
datatype to another?

For when you want to do one kind of conversion, but not allow another.
There are several different ways of converting values, and they all fit
in different situations.

CType(stringValue, Integer) will for example convert a null string into
zero, but that is not always desirable. Sometimes you want a null value
to be considered illegal, and not silently converted.

Another example is casting of a known type. The DirectCast method is a
slightly faster, and it will only allow casting a reference into it's
actual type.
 
Heikki Leivo said:
For backwards compatibility or for those who prefer to write in vb6
style.

Why is using the shorter, straight version "vb6 style"? These are all
commands, specialized on the destination type, that are even compiled
inline.


Armin
 
CType(x, Integer) is identical to CInt.
They will both convert a null string to zero.

In general, CType has identical behavior to the shorter CInt, CLng, etc.
macros (they aren't functions, but part of VB language syntax).
--
David Anton
http://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
 
Absolutely.
CType, CInt, CLng, etc. are all a legit part of VB syntax and are not
related to any legacy libraries.
--
David Anton
http://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
 
David said:
CType(x, Integer) is identical to CInt.
They will both convert a null string to zero.

Yes, of course. Other methods won't, like Int32.Parse for example.
 
Back
Top