Home  >  Article  >  Backend Development  >  The difference between value type pointing in PHP and C#_PHP Tutorial

The difference between value type pointing in PHP and C#_PHP Tutorial

WBOY
WBOYOriginal
2016-07-20 11:17:37739browse

The difference between value copying in PH and C# (if something is wrong, please point it out!)

 $a = 2;

 $b = $a; //In php, the address of b points to a, so b is also equal to 2 at this time; the difference is here

 $a = 5; //At this time, the value of a in php is rewritten, so the php core will reassign b to an address at this time, and then copy the original value of a. This is the principle of copy-on-write, which means that unless a write operation is performed, the value type points to an address.

And in C#. Copy of value types. Always create a new address, such as:

int a = 2;

 int b = a; //At this time, it does not matter whether a is written twice or not. .NET will allocate a new memory space to b (the value is stored in the stack space). Then copy the value of a

Note: In C#, values ​​of value types are stored directly on the stack. For reference types, the reference address is stored on the stack, and the actual value is stored on the heap. According to the address of the stack, find the value in the heap.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371975.htmlTechArticleDifferences in value copying between PH and C# (if something is wrong, please point it out!) $a = 2; $b = $a; //In php, the address of b points to a, so b is also equal to 2 at this time; the difference is here $a = 5; //At this time, p...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn