1. Type: value type reference type.
Classification by: How the type is allocated in memory. The value type is on the stack, and the reference type is in the managed heap.
noun : Stack-All variables are allocated on the stack, except that the value type directly contains the data, and the reference type contains an address that points to the managed heap object.
A variable that contains the address of an object on a heap is called a variable that refers to this object or variable that references this object .
value type : Simple Type (base Class library type alias) int byte etc.
Declaring an int type is actually a struct-type variable that declares a System.Int32 that contains all the fields in the value type (here, the struct)
Structure Enumeration
Reference type : Class delegate interface, etc.
2. Initialization of variables
Public struct Point { publicint x; } class program { staticvoid Main (string[] args) {point p;// The struct type variable itself is an instance of Console.WriteLine (p.x); // compiler hints may refer to Unassigned fields x should be preceded by p.x=10; Console.readkey (); } }
But there is another situation that passes directly and prints out 0. Note the difference. The reason is that the fields are also initialized when the class is initialized .
Public class Point { publicint x; } class program { staticvoid Main (string[] args) { new point ();//Note this must be initialized first, otherwise the compiler prompts for an unassigned local variable Console.WriteLine (p.x); Console.readkey (); } }
3. Object references are not set to an instance of an object, as shown in the following example. The reason for this is that a is an object reference, and no new has been pointed to any actual object.
Object A = null; Console.WriteLine (A.tostring ());
NET Basic Course--type foundation (NET Beauty)