Main content of this section: class and structure differences.
Ⅰ, class
In. NET, all classes eventually inherit from the SYSTEM.OBJETCT class, so it is a reference type, and the value of the object instantiated by the class is stored in the managed heap (managed heap);
Ⅱ, structural struct
A struct is a value type, and all structures inherit from the System.ValueType class, and instances are allocated in the stack of threads;
Ⅲ, why not use class to completely replace struct
There are several places where we should consider using struct instead of class:
A. When implementing a structure that is primarily used to store data, a struct can be considered;
The b.struct variable occupies the space of the stack, so it is only used when the data volume is relatively small;
C. Array of structures with higher efficiency;
D. provide compatibility for certain and unmanaged code communications.
"You must know. NET"-From behind: Class and struct (Ⅳ)