Connecting Tech Pros Worldwide Forums | Help | Site Map

type casting in VB.Net vs C#

JohnK
Guest
 
Posts: n/a
#1: Jul 21 '05
under the covers is type casting in VB.Net the same as C# ?
myObject = CType(..,..) in VB.Net vs
myObject = (SomeClass)aObject


Mattias Sjögren
Guest
 
Posts: n/a
#2: Jul 21 '05

re: type casting in VB.Net vs C#


[color=blue]
>under the covers is type casting in VB.Net the same as C# ?
>myObject = CType(..,..) in VB.Net vs
>myObject = (SomeClass)aObject[/color]

Not quite. CType performs conversion in addition to casting, so for
example the following works

Dim o As Object = "5"
Dim i As Integer = CType(o, Integer) ' or CInt(o)

but the following doesn't

object o = "5";
int i = (int)o;

In that sense, VB.NET's DirectCast operator is more of a strict
casting operator.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Closed Thread


Similar .NET Framework bytes