473,388 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Boxing and UnBoxing VB.NET vs C#

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
Jul 19 '05 #1
3 4940
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Jul 19 '05 #2
Thanks Mattias

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:#M**************@TK2MSFTNGP10.phx.gbl...
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

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

Jul 19 '05 #3
Thanks Mattias

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:#M**************@TK2MSFTNGP10.phx.gbl...
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

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

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: Mountain Bikn' Guy | last post by:
I have a situation where an app writes data of various types (primitives and objects) into a single dimensional array of objects. (This array eventually becomes a row in a data table, but that's...
3
by: Steve | last post by:
Hi, I have a class like: public ClassA { int vals1; int vals2; }
24
by: ALI-R | last post by:
Hi All, First of all I think this is gonna be one of those threads :-) since I have bunch of questions which make this very controversial:-0) Ok,Let's see: I was reading an article that When...
4
by: Peter Olcott | last post by:
I want to be able to make my .NET applications run just as fast as unmanaged C++. From my currently somewhat limited understanding of the .NET framework and the C# language, it seems that...
94
by: Peter Olcott | last post by:
How can I create an ArrayList in the older version of .NET that does not require the expensive Boxing and UnBoxing operations? In my case it will be an ArrayList of structures of ordinal types. ...
19
by: ahjiang | last post by:
hi there,, what is the real advantage of boxing and unboxing operations in csharp? tried looking ard the internet but couldnt find any articles on it. appreciate any help
161
by: Peter Olcott | last post by:
According to Troelsen in "C# and the .NET Platform" "Boxing can be formally defined as the process of explicitly converting a value type into a corresponding reference type." I think that my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.