I. Definition:
C # It is easy to define an empty type. Just add a question mark to a simple type symbol, for example:
Int? CC
In this way, an empty type is defined.
Ii. Initialization:
The biggest difference between the initialization of an empty type and the initialization of a non-empty type is that a null value can be allocated to an empty type. For example, the following methods are all possible:
Int? Cc = 10;
Int? Cc = NULL; (non-empty type cannot be initialized like this)
Iii. Use
It is actually very easy to use the null type. You only need to first determine that it is not null, you can use the following method
If (Cc = NULL)
{
........
}
Another method is: the null type has two attributes: hasvalue and value. The first one is used to determine whether it is null. If it is false,
If true is not returned, when the value of this attribute is true, you can use the value attribute to obtain its value, such as CC. value. Of course, you can also directly use CC without adding value.
If (CC. hasvaluesl)
{
........
}
Iv. type conversion
If you do not want to convert an empty type to a non-empty type, the conversion must be displayed.
The non-empty type can be implicitly converted to an empty type, as shown in the followingCode:
Int dd = (INT) CC; (In addition, the null value judgment code is missing, which is omitted)
Int? Cc = dd;