473,399 Members | 4,254 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,399 software developers and data experts.

what is ctype ?

9
what is ctype ???
Dec 25 '09 #1
2 1329
Frinavale
9,735 Expert Mod 8TB
CType is used for when you want to Cast an object of a Type into a different Type in VB.NET

In C# it's much easier. If you want to cast something into something else then you would just use:
Expand|Select|Wrap|Line Numbers
  1. Integer i;
  2. i = 5;
  3.  
  4. Double j;
  5. j = (Double) i;
This syntax cannot be used in VB.NET (probably because it uses brackets for so many things...arrays, functions etc) So, in VB.NET you either use the CType method or the DirectCast method to cast between object types:

Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer 
  2. i = 5
  3.  
  4. Dim j As Double = Ctype(i, Double)

All the information you need on the CType method and any other .NET controls can be found in the MSDN Library. There are multiple articles on the CType Function there. I recommend bookmarking the MSDN Library and using it as your primary resource when developing in .NET.

See How to: Define a Conversion Operator for a walk through on how to define a CType conversion operator (properly create the CType method) for your own custom classes!

-Frinny
Apr 15 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

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...
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
15
by: Marcel | last post by:
Hi, I've found some sample code to put some text into Word. I'm testing this code to learn from it, but I can't find an explanation for the use of CType in the following code. Can someone...
6
by: buc | last post by:
I have created a simple login keyboard with QWERTY keys with a user textbox and password textbox. When I press a key the text goes into both boxes....? The focus event on both boxes eval to TRUE....
9
by: Just Me | last post by:
Public Shared Function GetValue(ByVal keyName As String, ByVal valueName As String, Optional ByVal badKey As Object = "") As Object Dim UserKey As RegistryKey =...
5
by: Nathan Sokalski | last post by:
I have a DataList that I was having trouble getting the events for. After a bit of help, I realized that I needed to put the databinding inside an If Not IsPostBack() condition. Although this fixed...
48
by: Frederick Gotham | last post by:
The "toupper" function takes an int as an argument. That's not too irrational given that a character literal is of type "int" in C. (Although why it isn't of type "char" escapes me... ) The...
0
by: rsine | last post by:
I have created my first windows service and have found that it fails when I initially start it but when I immediately try to restart the service it starts. What could be causing this behavior? I...
3
navanova
by: navanova | last post by:
Hi there, I've used the following function as part of a code to connect my vb.net application to sql server 2000. However, the underlined code below (at the while statement) says: "Operator '=' is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.