Saved Bookmarks
| 1. |
What is Boxing and Unboxing in C#? |
|
Answer» The two functions are used for typecasting the DATA types: Boxing: Boxing CONVERTS value TYPE (int, char, etc.) to reference type (object) which is an implicit CONVERSION process using object value. Example: int num = 23; // 23 will assigned to numObject Obj = num; // BoxingUNBOXING: Unboxing converts reference type (object) to value type (int, char, etc.) using an explicit conversion process. Example: int num = 23; // value type is int and assigned value 23Object Obj = num; // Boxingint i = (int)Obj; // Unboxing |
|