Boxing Conversions

Unknown | 1:37 AM |

Boxing is the implicit conversion of a value type to a reference type or to any interface
type implemented by this value type. This is possible due to the principle of type system
unification where everything is an object.
When boxing occurs, the contents of value type are copied from the stack into the
memory allocated on the managed heap. The new reference type created contains a copy
of the value type and can be used by other types that expect an object reference. The
value contained in the value type and the created reference types are not associated in any
way. If you change the original value type, the reference type is not affected. Boxing,
thus, enables everything to appear to be an object, thereby avoiding the overhead required
if everything actually were an object.

Example:
VB.NET
Dim n as Integer = 10
Dim obj as Object
obj = n


Explanation:
In the above code segment, a value-type variable n is declared and is assigned the value
10. The next statement declares an object-type variable obj. The last statement implicitly
performs boxing operation on the variable n.

Category:

About http://dotnetvisual.blogspot.in/:
DOT NET TO ASP.NET is a web application framework marketed by Microsoft that programmers can use to build dynamic web sites, web applications and web services. It is part of Microsoft's .NET platform and is the successor to Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common Language Runtime, allowing programmers to write ASP.NET code using any Microsoft .NET language. create an application very easily ....