Qus:    What do you know about boxing and unboxing?
Oct 22, 2020 08:35 2 Answers Views: 863 SAI
Prev Next
Answers (2)
SWEETY Oct 23, 2020 02:46
Answer:   Boxing
Converting a value type to the type object
eg : obj myObject = i;

Extracting the value type from the object
eg : i = (int)myObject;

PARTH Oct 23, 2020 08:25
Answer:   Boxing - It is the process of converting a value type to the object type or any interface type implemented by this value type. Boxing is implicit.

Example: Boxing Copy
int i = 10;
object o = i; //performs boxing

In the above example, the integer variable i is assigned to object o. Since object type is a reference type and base class of all the classes in C#, an int can be assigned to an object type. This process of converting int to object is called boxing.

Unboxing - It is the reverse of boxing. It is the process of converting a reference type to value type. Unboxing extract the value from the reference type and assign it to a value type.

Unboxing is explicit. It means we have to cast explicitly.

Example: Unboxing Copy
object o = 10;
int i = (int)o; //performs unboxing

Post Your Answer
Guest User

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.

Let`s Connect