|
|
|
date: Thu, 30 Aug 2007 19:56:02 -0700,
group: microsoft.public.dotnet.academic
back
Re: When to use variables, objects and CTYPE?
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" wrote in message
news:20A3E762-5DC3-409E-ACBB-192BD3864046@microsoft.com...
> Hello
> Under what conditions "must" you use "CTYPE" when working with variables
> and
> objects?
date: Tue, 27 Nov 2007 21:57:26 -0500
author: Wannano
|
|