in Education by

What is the difference between boxing and unboxing in C#?

1 Answer

0 votes
by
Boxing and Unboxing are both used for type converting, but have some differences:
 
Boxing
 
Boxing is the process of converting a value type data type to the object or to any interface data type which is implemented by this value type. When the CLR boxes a value means when CLR converting a value type to Object Type, it wraps the value inside a System.Object and stores it on the heap area in the application domain. 
 
Example
 
ASP.NET
 
Unboxing
 
Unboxing is also a process that is used to extract the value type from the object or any implemented interface type. Boxing may be done implicitly, but unboxing has to be explicit by code. 
 
Example:
 
 
ASP.NET
 
The concept of boxing and unboxing underlies the C# unified view of the type system in which a value of any type can be treated as an object.
 

Related questions

0 votes
    What is Boxing and Unboxing in C#?...
asked Jul 9, 2021 in General by JackTerrance
0 votes
    What is the difference between late binding and early binding in C#?...
asked Mar 31, 2021 in Education by JackTerrance
0 votes
    What is the difference between String and StringBuilder in C#?...
asked Mar 31, 2021 in Education by JackTerrance
0 votes
    What is the difference between Static and Dynamic resources?...
asked Apr 9, 2021 in Education by JackTerrance
0 votes
    What is the difference between MVP, MVC and MVVM?...
asked Apr 9, 2021 in Education by JackTerrance
0 votes
    What is the difference between Server.Transfer and Response.redirect?...
asked Apr 7, 2021 in Education by JackTerrance
0 votes
    What is the difference between HttpContext.Current.Items and HttpContext.Current.Session in ASP.NET?...
asked Apr 7, 2021 in Education by JackTerrance
0 votes
    What is the Difference between session and caching?...
asked Apr 7, 2021 in Education by JackTerrance
0 votes
    What is difference between MVC and Web Forms?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
    What is the difference between WCF and Web services?...
asked Apr 1, 2021 in Education by JackTerrance
0 votes
    What is a Hashtable in C#?...
asked Apr 1, 2021 in Education by JackTerrance
0 votes
    What is Serialization in C#?...
asked Apr 1, 2021 in Education by JackTerrance
0 votes
    What is IEnumerable in C#?...
asked Mar 31, 2021 in Education by JackTerrance
0 votes
    What are sealed classes in C#?...
asked Mar 31, 2021 in Education by JackTerrance
0 votes
    What are extension methods in C#?...
asked Mar 31, 2021 in Education by JackTerrance
...