(Value Type reference type) Relationship with null, reference null
1. nullNull indicates that the variable does not point to any object.
2. Value TypeIncluding bool, struct, enumeration, int, double, float, and so on. The value types in. NET are inherited from ValueType.
3. Reference TypeIncluding strings, arrays, classes, interfaces, etc. The reference types in. NET are inherited from objects.
4. Reference Type and nullPerson p1 = new Person (); // The defined p1 does not point to any point at this time! P1 = null; p1.SayHi (); -------------- after executing the above Code, an exception is thrown directly. We are very familiar with not referencing the object to the object instance NullReferenceException. This is the relationship between the reference type and null. When a reference type is null, it means that he has no point.
5. Value Type and null// If this is the case in the project. Int num = null; // you don't have to wait to throw an exception because the compiler will directly report an error. Because the value type cannot be null. What if I want int num to be null? See 6th.
6. Empty data type.In. NET, by default. The data type that can be null is the reference type. The empty data type cannot be a value type. How can we control the value type? It can be written in this way. // Add? Indicates that the int type can be empty. It is called an int of the null type. Int? Num = null; // This method is widely used in Entity classes in database applications. A field in the database can be empty. // The attributes in the object class should also be empty. This is used.