HighTechTalks DotNet Forums  

When to use variables, objects and CTYPE?

Dotnet Academic General Discussions microsoft.public.dotnet.academic


Discuss When to use variables, objects and CTYPE? in the Dotnet Academic General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
=?Utf-8?B?d2lubGlu?=
 
Posts: n/a

Default When to use variables, objects and CTYPE? - 08-30-2007 , 10:56 PM






Hello
Under what conditions "must" you use "CTYPE" when working with variables and
objects?

Reply With Quote
  #2  
Old   
PvdG42
 
Posts: n/a

Default Re: When to use variables, objects and CTYPE? - 08-31-2007 , 07:55 PM






"winlin" <winlin (AT) verizon (DOT) com> wrote

Quote:
Hello
Under what conditions "must" you use "CTYPE" when working with variables
and
objects?
Can you provide some sort of contextual information on what you want to do
that you believe needs ctype?
Normally, if I need to make a specific conversion that requires "forcing, I
use explicit_cast<type>(argument).



Reply With Quote
  #3  
Old   
Wannano
 
Posts: n/a

Default Re: When to use variables, objects and CTYPE? - 11-27-2007 , 09:57 PM



You must use CType when your code has the OPTION STRICT ON either in the
project properties or in the VB Code itself and when the conversion is a
narrowing one.

For instance, you can always write: Dim i as Integer
Dim d as Double = i
But if you have set "Option strict On" in the project properties or in the
code, Dim d as Double

Dim i as Integer = d will not
compile,

you have to write: Dim d as Double

Dim i as Integer = CType(d, double)
(it's a way to tell the compiler that you know what you are
doing)
For objects, if Customer Inherits from Person, you can always write: Dim C
as new Customer

Dim P as Person = C
But with Option Strict On, if you write Dim C as new Customer
Dim P as Person =
C
Dim D as Customer
= P, the compiler will not accept the last statement
it will accept: Dim C as new Customer
Dim P as Persomn = C
Dim D as Customer = CType(P, Customer)

I hope I am clear enough. Sometimes my students understand what I say.

Marc Biotteau, MCT

"winlin" <winlin (AT) verizon (DOT) com> wrote

Quote:
Hello
Under what conditions "must" you use "CTYPE" when working with variables
and
objects?



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.