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
what is silver light when will we use silver light,
How to find last error which occurred?
What is the appSettings Section in the web.config file?
What is localhost in asp.net?
What is asp net application object?
Why do we use asp.net?
How will you do windows authentication and what is the namespace? If a user is logged under integrated windows authentication mode, but he is still not able to logon, what might be the possible cause for this? In ASP.Net application how do you find the name of the logged in person under windows authentication?
Which protocol is used in a web api?
Describe a Windows Service and its lifecycle ?
Can we have multiple master pages in asp net?
What is difference between session and viewstate?
Explain the features that make asp.net more used framework? : asp.net mvc
Which type if caching will be used if we want to cache the portion of a page instead of whole page?
What are the server control tags in asp.net.?
What are the types of caching in asp.net?