Home > Net >  Packing and unpacking
Packing and unpacking

Time:01-14

There are a piece of code

 
Int i1=2;
The object o1=i1;
The object o2=o1;

Object. ReferenceEquals (o1, o2). Dump ();//true

O1=5;

O1. Dump (" o1 ");//return 5
O2. Dump (" o2 ");//return 2


The above code, i1 for int value types, then assigned to the object o1 for packing process and become a reference type, then o1 assigned to o2 (according to the characteristics of a reference type, the actual values should be stored in a Heap Heap, Stack and the Stack to store reference address, the result should be consistent), would you please tell me why why to o1 to assign a value does not affect the value of o2?

CodePudding user response:

 
O1=5;//this is your new packing
  •  Tags:  
  • C#
  • Related