473,385 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 5177
"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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.