Why string is a reference type values not be modified

 

 

C # data types into a value type and reference type. Simple value type of operation, reference types more space.

C # A total of 15 predefined types, wherein the value type 13 (8 integer, two floating point types, decimal, bool, char), 2 citations type (string, object).

Look carefully, and value types are space using a smaller type, a reference type is space using a larger type (such as string, like our own declaration).

 

string because space is the use of larger high probability, it is used as a reference type. However, if the reference type and the general assignment of the same, so easy to be modified without the need for changes.

So, Microsoft gave the compromise, the value of each change, will give a new address to a variable. The original address or the original value, their changes do not affect others.

In this way, string both reference type of performance, but also the value of the type of convenience.

 

Guess you like

Origin www.cnblogs.com/wangliuwei/p/11129767.html