© { JSL }
42
Unboxing
·
unboxing copies the boxed value back again
w
this requires an explicit cast to
exact
type
w
if the target type is wrong - InvalidCastException
struct
Pair
{
public int
X, Y;
...
}
static void
Function()
{
Pair p =
new
Pair(1,2);
object
o = p;
p.X = p.Y = 0;
Pair q = (Pair)o;
}
p.X
stack
heap
0
0
p.Y
.X
1
2
.Y
@
o
cast
q.X
1
2
q.Y
box
unbox