The difference between PH and C# value copy (If something is wrong, I hope to point it out!)
$a = 2;
$b = $a; //In php, point the address of b to a, so b is also equal to 2 at this time; the difference lies in this
$a = 5; //At this time, the value of a in php is rewrite again, so the php core will reassign b an address and then copy the original value of a. This is the copy-on-write principle, that is, unless a write operation is performed, the value type points to an address.
And in C#. Copy of value type. Always create a new address like:
int a = 2;
int b = a; //At this time, no matter whether a is secondary write or not. .NET will allocate a new memory space to b (the value exists in the stack space). Then copy the value of a
Note: Values of value types in C# are stored directly on the stack. For reference types, the reference address is stored in the stack, and the actual value is stored in the heap. Find the values in the heap according to the address of the stack.
$a = 2;
$b = $a; //In php, point the address of b to a, so b is also equal to 2 at this time; the difference lies in this
$a = 5; //At this time, the value of a in php is rewrite again, so the php core will reassign b an address and then copy the original value of a. This is the copy-on-write principle, that is, unless a write operation is performed, the value type points to an address.
And in C#. Copy of value type. Always create a new address like:
int a = 2;
int b = a; //At this time, no matter whether a is secondary write or not. .NET will allocate a new memory space to b (the value exists in the stack space). Then copy the value of a
Note: Values of value types in C# are stored directly on the stack. For reference types, the reference address is stored in the stack, and the actual value is stored in the heap. Find the values in the heap according to the address of the stack.