Differences:
1. The value type is usually allocated to the stack, and its variables directly include instances of variables, which is highly efficient.
2. The reference type is assigned to the managed stack. A variable of the reference type usually contains a pointer to the instance through which the variable references the instance.
3. The value type inherits from ValueType (Note: System. ValueType inherits from System. Object), while the reference type inherits from System. Object.
4. Value Type variables include instance data. Each variable stores its own copy of data. Therefore, by default, parameter passing of value type does not affect the parameter itself; the reference type variable saves the reference address of its data, so the parameter itself will be affected when passing parameters in reference mode, because the two variables will reference the same address in memory.
5. There are two types of values: binning and unboxing. The reference type can only be boxed. I will discuss this topic in detail in the next section.
6. Typical value types include struct, enum, and a large number of built-in value types. classes can be referred to as reference types.
7. The memory of the value type is not controlled by GC (garbage Collection, Gabage Collection). When the scope ends, the value type is automatically released, reducing the pressure on the managed heap, therefore, it has performance advantages. For example, struct is generally more efficient than class, and GC is used to recycle reference-type memory. Microsoft even recommends that you do not release the memory on your own.
8. The value type is sealed. Therefore, the value type cannot be a base class of any other type, but can be a single inheritance or multiple inheritance interfaces. The reference type generally has inheritance.
9. The value type does not have polymorphism, but the reference type has polymorphism.
10. The value type variable cannot be a null value. The value type is initialized to a value of 0. By default, the referenced type variable is created as a null value, indicates that there is no reference address pointing to any managed heap. An NullReferenceException is thrown for any operation of the reference type whose value is null.
11. The value type has two statuses: boxed and unboxed. The runtime provides the boxed form of all value types, while the reference type usually has only one format: boxed.