1. Value-type data is stored in the memory stack; reference-type data is stored in the memory heap, while memory units only store
Address.
2. Fast value-type access and slow reference-type access.
3. The value type indicates the actual data, and the reference type indicates the pointer or reference to the data stored in the memory heap.
4. The value type inherits from system. valuetype, and the reference type inherits from system. object.
5. The stack memory allocation is automatically released, and the stack will be released by GC in. net.
6. variables of the value type directly store the actual data, while variables of the reference type store the data address, that is, object reference.
7. The Value Type Variable directly stores the value of the variable in the stack, and the reference type variable stores the actual data address in the stack, while the actual
The data is stored in the heap. Note that the heap and stack are two different concepts, with different storage locations in the memory. The heap is generally used for storage.
Variable-length data, such as the string type, while the stack is used to store data of fixed length, such as integer data int (each int variable
Occupies four bytes ). It can be learned from the data storage location that when one value variable is assigned to another value variable, two values are saved in the stack.
And assign a reference variable to another reference variable. The two references to the same heap location are saved in the stack.
That is, the address of the same heap is saved in the stack. During data operations, each variable has its own value type,
Therefore, operations on a variable will not affect other variables. For variables of the reference type, operations on the data of a variable are
Variables in the heap are operated. If two referenced variables reference the same object, the actual meaning is that they are saved in the stack.
The address of the heap to be stored is the same. Therefore, operations on a variable will affect another variable that references the same object.