First, predefined types.
1, value type and reference type
Data types in C # can be classified into value types and reference types, value types are stored on the stack, and reference types are stored on the managed heap.
The following code example,
int i=10;
int j=i;
The values of I and J are all 10, and in memory there will be two places to store 10.
And look at the code below.
Vector x=new Vector();
x.Value=20;
Vector y=x;
Console.WriteLine(y.Value);
y.Value=50;
Console.WriteLine(x.Value);
Vector is a reference type, and a reference type requires new to instantiate one when it is used. After this code executes, there is only one vector object, and x,y points to the memory address that contains the object. Because X,y stores all references to objects, x changes as y changes. So the results of the program output are 20 and 50.
If a variable is a reference, you can set its value to NULL to indicate that it does not point to any object.
2, CTS type.
The predefined types of C # are not placed inside the language, but are placed inside the. NET framework, such as declaring an int type, actually. NET structure, an instance of System.Int32. This means that you can think of all the basic data types as classes that support certain methods.