Why at this point, the value of T is still 20 and not 100 ?
Because you didn't modify t
.
You'll want to look up "boxing". But, what's going on in your code is that the value 20
stored in i
is "boxed", which means a new reference type object is allocated and the value 20
is copied into that object.
When you assign r = t
, you copy the reference of that boxed value to t
. So far, so good.
But, when you assign r = 100;
, you have not modified the boxed value. The original boxed value remains the same, but now is referenced only by t
.
The assignment r = 100
creates a whole new boxed value, allocated on the heap, and copies the reference to that object into the variable r
. This has no effect on t
, which remains set to the reference of the first boxed value of 20
.