Difference between Boxing and Unboxing in C# with Example

Use of Boxing and Unboxing in C#

C# is a strongly-typed language. Boxing and Unboxing are the most important concepts you always get asked in your job interviews. So in this article we will talk about understanding on Boxing and UnBoxing in C# Programming Language with Example.

C# Boxing and UnBoxing

Boxing and Unboxing is a  essential concept in .Net’s type system. With Boxing and Unboxing one can link between value-types and reference-types by allowing any value of a value-type to be converted to and from type object. 

Boxing is the process of converting a value type to the reference type.
Unboxing is the process of converting a reference type to value type
Type of Conversion:
Implicit Conversion
Explicit Conversion

C# Example:
int i = 221;
object obj = i; //boxing
object obj = 213;
i = (int)obj ; // unboxing

I hope you will enjoy the C# interview tips while preparing for an interview. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome. 

Also If you like this article, don't forget to share this article with your friends and colleagues.
Difference between Boxing and Unboxing in C# with Example Reviewed by Ravi Kumar on 2:58:00 PM Rating: 5


All Rights Reserved by Etechpulse © 2012 - 2017
Powered By Blogger

Contact Form


Email *

Message *

Powered by Blogger.