Value type: All references to value types are stored in the stack
Value type Assignment principle: The true value copied on the stack
Reference type:
Properties of real objects on the heap that are stored on the real object itself
(1) Open space on the heap to save data
(2) The memory address on the heap is stored in the stack space
(3) Pointing from the stack to the real object on the heap
For value types, different variables are allocated different storage spaces, and the value of the variable is stored in the storage space.
The value of the variable is passed by the assignment operation, and changing one variable does not affect the value of the other variable.
For reference types, the assignment is to pass a reference to the original object to another reference. Array.
When an array reference is assigned to another array reference, the two references point to the same array, which is to point to the same block of storage space
Structure:
Definition of structure
Grammar:
Access modifier struct struct name {//struct}
You can have fields in the @ structure, or you can have methods
When @ is defined, the fields in the struct cannot be assigned an initial value
@ You cannot have attributes when you are not going to the new struct class
After you declare an object of a struct, you must assign an initial value to all members of the struct.
Packing and unpacking
A value type is converted to a reference type to be boxed, and vice versa to be a unpacking
Reference method parameter passing
(Basic data types, such as, shape, float, character, bool, and struct are value types; arrays, interfaces and classes are reference types)
When a value type parameter is passed using a value method (without a ref decoration), the modification of the parameter in the method does not persist
When a reference type parameter is passed using a value method (without a ref decoration), the modification of the parameter in the method is preserved
When you pass a value type or reference type parameter by using a reference method (with ref decoration), the modification of the parameter in the method is preserved
Drill down into C # data types