One: value types and reference types
1. Value type:
Value types originate from the System.value family, and each object of value type has a separate memory area for saving its own values, value types
Where the memory area is called a stack (stack), it is saved in the memory area as long as it is modified in the code.
(for value types, different variables are allocated different storage spaces, and the value of the variable is stored in storage space.) Assignment operation
The value of the variable is passed, changing the value of one variable does not affect the value of the other variable)
Example code:
Class program{
static void Main (string[] args)
{
int Heightzhang = 170;
int heightli= Heightzhang;
Console.WriteLine ("Last year-Zhang Hao's height is:" +heightzhang+ ", Li Ming height is:" + Heightli);
Heightli = 180;
Console.WriteLine ("This year-Zhang Hao's height is:" +heightzhang+ ", Li Ming height is:" + Heightli ");
}
}
2. Reference type:
Reference types originate from the System.Object family, and in C # Reference types mainly include arrays, classes, interfaces, and so on. The memory area where the reference type resides
Two. Structural body
1. Definition:
Access modifier struct struct name
{
Structural body
}
(1) Structs can have fields, methods, fields cannot be assigned initial values.
(2) can not new, but conditional, the struct has member variables and member methods, member variables are not assigned, call member methods, not new will error, so generally first new.
Three: Box packing and unpacking
The process of converting a value type to a reference type is called boxing, which is called unpacking
Practical development to avoid loading/unpacking as much as possible
Reason:
Loading/unpacking can reduce program performance
Four: Different types of parameter passing
Overview:
With value passing, changes to parameter values in a method cannot be persisted after the call.
Passed using ref mode, you can preserve changes to the parameter values.
Drill down into C # data types