Value type: Duplicates the real value (stack) on the stack, mainly including data types (int,float,double and enumerations, etc.)
Value types originate from: System.ValueType
References to all types of reference types exist in the stack.
Reference type: The Real object property (heap) of real objects stored on the heap, mainly including (classes, interfaces, arrays)
Value types originate from: System.Object
Methods and Features:
public void Say () {
}
(1) Return value
(2) Access modifiers
(3) Method name
(4) Method body
(5) Parameters of the method
Definition of structure:
Access modifier struct struct name {
Structural body
}
You can have fields in the structure, or you can have methods
When defined, a field in a struct cannot be assigned a value
Packing and unpacking
The process of converting a value type to a reference type is called boxing, which is called unpacking
Unnecessary packing and unpacking should be minimized and the performance loss is greater.
Value parameter passing:
Reference 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
In-depth C #