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 *

Captcha *