search
Login

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

0 votes
30 views
asked Expert 13.2k points 27 40 59

2 Answers

0 votes
When a value type is converted to an object type, the process is known as boxing; whereas, when an object type is converted to a value type, the process is known as unboxing. 
 
Boxing and unboxing enable value types to be treated as objects. Boxing a value type packages it inside an instance of the Object reference type. This allows the value type to be stored on the garbage collected heap. Unboxing extracts the value type from the object. In this example, the integer variable i is boxed and assigned to object obj.
 
Example:
int i = 123;
object obj = i; /* Thi line boxes i. */ 
 
/* The object obj can then be unboxed and assigned to integer variable i: */
i = (int)obj; // unboxing 
 
answered Guru 24.6k points 29 52 81
0 votes
Implicit (manual) conversion of value type to reference type of a variable is known as BOXING, for example integer to object type conversion. Conversion of Boxed type variable back to value type is called as UnBoxing.
answered Geek 15.3k points 16 41 63

Related questions

0 votes
1 answer 22 views
22 views
asked sara Guru 24.6k points 29 52 81
0 votes
1 answer 68 views
68 views
asked john Guru 27.1k points 31 50 97
0 votes
2 answers 11 views
11 views
asked keem Expert 13.2k points 27 40 59
0 votes
3 answers 178 views
178 views
asked daniel Advisor 5.6k points 1 7 14
0 votes
1 answer 15 views
15 views
asked smith Geek 15.3k points 16 41 63
...