© { JSL }
42
Text Box: Unboxing
Unboxing
·unboxing copies the boxed value back again
wthis requires an explicit cast to exact type
wif 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