Explain The Concept Of Boxing And Unboxing ?

please explain about the Concept Of Boxing And Unboxing in .net

framework.

Last updated:12/12/2019 10:45:15 PM

1 Answers

Nishi Tiwari
Nishi Tiwari

Boxing and unboxing is an important concept in C#. In C# there are three types of data type, value types (int, float), reference type (object, string) and pointer type. C# allows to convert vale type to reference type and vice versa. Boxing and unboxing enables to a unified view of type system in which any type of value can be treated as an object.

Boxing can be defined as a process of converting vale data type to a reference data type. It is used by object type and it is an implicit conversion. Value type and referenced type stored in stack and heap respectively.

For example

 int num=23 ;

Object obj=num;

Explain The Concept Of Boxing And Unboxing ?

Unboxing can be defined as the process of converting reference type to value type. It is a reverse process of boxing and it as an explicit conversion.

For example

int num=23;

Object obj=num;
 int i=(int)obj;

Explain The Concept Of Boxing And Unboxing ?

Answer