472,989 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

Why use anything besides Ctype to convert datatypes?

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?
Sep 19 '07 #1
8 5167
"winlin" <wi****@verizon.comschrieb
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
Sep 19 '07 #2
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-
Sep 19 '07 #3
winlin wrote:
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.

--
Göran Andersson
_____
http://www.guffa.com
Sep 19 '07 #4
"Heikki Leivo" <he************@cadworksdotfi.removethisschrieb
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.
Why is using the shorter, straight version "vb6 style"? These are all
commands, specialized on the destination type, that are even compiled
inline.
Armin

Sep 19 '07 #5
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
"Göran Andersson" wrote:
winlin wrote:
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.

--
Göran Andersson
_____
http://www.guffa.com
Sep 19 '07 #6
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
"Armin Zingler" wrote:
"Heikki Leivo" <he************@cadworksdotfi.removethisschrieb
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.

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

Sep 19 '07 #7
David Anton wrote:
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.

--
Göran Andersson
_____
http://www.guffa.com
Sep 20 '07 #8
Hello! Good Site! Thanks you! uibdbmfwnwwdw
Nov 23 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Joeri | last post by:
Hi, I'm struggling with this issue, maybe someone has already solved ik before. Here's the problem I Have : clsA witch is a base class clsB inherits from clsA clsC inherits from clsA clsD...
1
by: Logan X via .NET 247 | last post by:
It's official....Convert blows. I ran a number of tests converting a double to an integer usingboth Convert & CType. I *ASSUMED* that CType would piggy-back ontop of Convert, and that performance...
3
by: Mark Kamoski | last post by:
Hi-- What is the difference between Convert.ToString(obj) and CType(obj, String)? (Assume obj is a variable of type Object.) Please advise. Thank you.
4
by: Mike Cooper | last post by:
There is something about inherited classes I evidently don't know... I wrote the following class: Class Class1 inherits System.Windows.Forms.DataGridTextBoxColumn End Class There is...
6
by: Ot | last post by:
I apparently have a bit to learn about Casting and Conversion. I have been thinking of them as the same but a discussion in another thread leads me to believe that this is wrong thinking. I...
8
by: John A Grandy | last post by:
could someone please discuss the pros and cons of CType(MyDouble,Decimal) versus Convert.ToDecimal(MyDouble) .... and other such conversions ...
7
by: Brian Henry | last post by:
is there any speed diffrences between doing Ctype or directcast? I know about the inherite diffrences, but process usage time wise, does one take up more cycles then the other? thanks
3
by: FB's .NET Dev PC | last post by:
I'm trying to create a general-purpose routine to update a value in a data location on a remote server. The client-server protocol is OPC, but that isn't immediately important to my question. The...
4
by: Todd Plambeck | last post by:
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...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.