1) first define a structure
Struct person
{
Public int age;
}
2) Then pack the Value Type
Static void main (string [] ARGs)
{
Person P = new person ();
P. Age = 1;
// Bind the Value Type
Object OBJ = P;
P. Age = 2;
Console. writeline (P. Age );
Console. writeline (person) OBJ). Age );
}
Final result output: 2 and 1
Summary:
When the value type is boxed, a copy of the current value type is actually obtained, instead of being referenced (usually references are passed between classes ), to put it simply, the information of this value type is copied to OBJ. After copying, OBJ no longer depends on the original person p. the re-assignment of age does not affect obj.
If it is not a struct person but a class person, the final output result will be 2, because the reference to Variable P is assigned to OBJ.
In the same way, if a variable of the int equivalent type is packed, the result will be the same as above.