Boxing and UnBoxing VB.NET vs C#

  • Thread starter Thread starter Andy Read
  • Start date Start date
A

Andy Read

Dear all,

From the following examples. Can anyone please tell me why the C# IL
produces the unbox statement and the VB doesn't?

* Forgive me if the code isn't perfect, I don't have VS.NET on my internet
machine!

VB

Dim X as Integer
Dim Y as Object = X '** Box here.
X = CType(X,Integer) '** No Unbox here??


C#

int X;
Object Y = X; // Box here
X = (int) Y; // Unbox here

Many Thanks

Andy Read
 
Andy,
From the following examples. Can anyone please tell me why the C# IL
produces the unbox statement and the VB doesn't?

If you use the DirectCast operator intead of CType, you'll get an
unbox instruction. CType calls into the VB library to support
conversion in addition to casting and unboxing.



Mattias
 
Thanks Mattias

Mattias Sjögren said:
Andy,


If you use the DirectCast operator intead of CType, you'll get an
unbox instruction. CType calls into the VB library to support
conversion in addition to casting and unboxing.



Mattias
 
Thanks Mattias

Mattias Sjögren said:
Andy,


If you use the DirectCast operator intead of CType, you'll get an
unbox instruction. CType calls into the VB library to support
conversion in addition to casting and unboxing.



Mattias
 
Back
Top