What is boxing and unboxing ?
Answer Posted / narayansahu
Boxing and Un-boxing
Boxing allows value types to be implicitly treated like
objects.
Dim i As Integer = 5
i.ToString() ' i --> object --->object.tostring
OR
Dim i As Integer = 5
Dim obj As Object = i ' implicit boxing
obj.ToString()
OR you can do it explicitly
Dim obj As Object = CType(i, Object) ' un-necessary
explicit boxing
On the other hand, un-boxing is an explicit conversion from
object type to value type.
Dim i As Integer = 5
Dim obj As Object = i ' implicit boxing
Dim j As Integer = CType(obj, Integer) ' explicit un-boxing
? Boxing and Un-boxing is the transformation between
value type and object type while casting just transforms
the apparent (reference) type of objects.
? Value types are stored at the stack and objects are
stored at the heap.
Boxing takes a copy of value types from the stack to the
heap while un-boxing takes value types back to the stack.
On the other hand, casting does not physically move or
operate on an object. Casting merely changes the way
objects are treated in a program by altering their
reference type.
| Is This Answer Correct ? | 23 Yes | 6 No |
Post New Answer View All Answers
Difference between DataGid and Girdview? Difference b/w .Net 2.0, 3.0 and 3.5 ? Diff b/w dispose & Finialize Methods?
What is the mvc model?
What is session and application variable in asp net?
Explain the different parts that constitute ASP.NET application?
a web application needs to be created to accept the product name and quantity of a toy from a customer. After the customer has entered the product name the application needs to display the discounted price of the product to the customer (company is offering 35% discount on all products). The application should allow the customer to select the product name from a list box. and also while i'm data binding to a label with custom data binding with some declarations : "The Discounted Price is "+((System.Convert.todouble(lblprodprice.text)*(system.convert.todouble(txtqty.text)) - ((System.convert.todouble(lblprodprice.text)*(system.convert.todouble(txtqty.text)*0.35)). Where i need to give this declaration in asp.net 2.0.
What is the default authentication mode for asp.net?
List the advantages and disadvantages of user control an custom control?
How do session tokens work?
If I have more than one version of one assemblies, then how will I use old version (how/where to specify version number?) In my application?
What is odata in web api?
Explain Session state management options in ASP.NET.
Explain the advantages of caching?
What is the web.config file in asp?
What does asp stand for in asp.net?
Can you explain composite pattern?