Directory of Open Source for Quantitative Finance and Trading
Username: Password: Not registered?
 
Quick Search:    (AJAX based: No need to press button)

QuantCode Forum Index
   QuantFinance
     why is boxing/unboxing done in c#
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
mark72
Posted on: 2011/1/10 15:24
Just popping in
Joined: 2011/1/7
From:
Posts: 7
why is boxing/unboxing done in c#
i understand this is required for changing valuetype to object type, but i haven't been able to find a satisfactory answer or an example application of why it might be required to change type.
vanna
Posted on: 2011/2/21 0:25
Just can't stay away
Joined: 2007/3/21
From:
Posts: 104
Re: why is boxing/unboxing done in c#
One example situation is when you want to do deep copy instead of shallow copy or vice versa. (if you recall, reference type assigment creates a shallow copy while value type assigment creates a deep copy)

An interesting thought is why is it called "Boxing" - I was wondering if it is boxing in the sense of fighting?? Now I found out that it is boxing in the sense of placing something in a box. for example, if I convert a value type to a reference type the MSIL code emitted by the compiler will place the value type inside a refernce type box, but very well knows that the actual object contained within it is a value type. Unboxing is able to determine the underlying reference/value type, and resurrects back the correct type.


----------------
Please support Barsana eye camp

theologis
Posted on: 2011/2/22 17:17
Just popping in
Joined: 2010/2/14
From:
Posts: 3
Re: why is boxing/unboxing done in c#
Hi guys,

One remark regarding boxing/unboxing:
For sure, if someone can avoid it, then this is great for performance reasons. Code that uses heavily boxing/unboxing becomes also.. quite slow.

Theologis

Quote:

vanna wrote:
One example situation is when you want to do deep copy instead of shallow copy or vice versa. (if you recall, reference type assigment creates a shallow copy while value type assigment creates a deep copy)

An interesting thought is why is it called "Boxing" - I was wondering if it is boxing in the sense of fighting?? Now I found out that it is boxing in the sense of placing something in a box. for example, if I convert a value type to a reference type the MSIL code emitted by the compiler will place the value type inside a refernce type box, but very well knows that the actual object contained within it is a value type. Unboxing is able to determine the underlying reference/value type, and resurrects back the correct type.
Threaded | Newest First Previous Topic | Next Topic | Top

Register To Post
 
Similar Links:
Copyright © 2011 QuantCode Inc. All rights reserved.