What is Boxing and Unboxing in C#

What is Boxing and Unboxing in C#


The Boxing and Unboxing are concept of Values Types and Reference Type.

Boxing :-
Boxing is conversion from Value Type to Reference Type (Object).
Converting a value type to reference type is called Boxing.


int m=125;

object p=m; // here we boxing m;
class MYTES

int i=1;
object o=i; // boxing
int j=(int) o; //unboxing


Unboxing: -
UnBoxing is conversion from Reference Type(Object) to Value Type.


m = 123;
i = (int)m;  // unboxing proccess

Leave a Reply

Your email address will not be published. Required fields are marked *

9 + 3 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">