.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Boxing and Unboxing in C#

Posted By:Abhisek Panda       Posted Date: November 28, 2009    Points: 15    Category: C#    URL: http://www.dotnetspark.com  
 

C# provides flexibility to convert value type into reference type and vice verse by boxing and unboxing operations.

Boxing


        When value type is converted into reference type it is called as boxing. It is done implicitly.

         When parameters are passed inside any method and it need the reference type, the compiler automatically converts it.

Unboxing


         Opposite to boxing when the reference type is converted to value type it is called as unboxing. It is not done implicitly. We have to do it explicitly.

Example:
int i = 20;
object o;
o = i;//Boxing
int j = (int)o;//Unboxing using type casting
 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend