type casting in VB.Net vs C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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

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
 
Back
Top