Latest

random

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
Unboxing
Definition:
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.

3 comments:

All Rights Reserved by Etechpulse © 2015 - 2016
Powered By Blogger

Contact Form

Name

Email *

Message *

Powered by Blogger.