473,545 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5192
"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(stringVal ue, 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. removethisschri eb
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(stringVal ue, 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. removethisschri eb
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
6556
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 inherits from clsA
1
1787
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 would be identical. I was 100% incorrect. The code below produces the results: CType Took: 0.2187528 seconds. Convert Took: 12.187656 seconds.
3
21405
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
3819
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 absolutely no added functionality to it.
6
10816
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 found this in the VB Language reference: <quote> The DirectCast keyword introduces a type conversion operation. You use it the same way you use the...
8
7341
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
2709
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
2165
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 part that is important is that the value passed to the server has to be the correct data type. I am trying to convert the input (as an object) to...
4
4857
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 equivalent for converting objects. Thanks, Todd
0
7479
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7411
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7773
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4962
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
722
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.