08. C # System. Nulable <T> and null reference operators (Chapter 4 4.2-4.4 ),
After reading these three sections, I found that the author was too detailed and told me how to use one of them normally. I don't know how to understand the author's painstaking efforts, I suggest you give me a brief explanation of the meaning of the author. It is too deep to really say it.
1. The core part of the null type is System. Nullable <T>. In addition to this, there are also tool methods provided by the static class System. Nullable.
2. Nullable <T> is a generic type, and type parameter T is a value type constraint.
The 3. T type is the basic type that can be empty.
4. Nullable <T> has two constructor functions: one is used to create an instance without a value, and the other is used as the value of a receiving T.
1 Nullable<int> n = new Nullable<int>();2 Nullable<int> n1 = new Nullable<int>(1);
5. The framework provides two conversions: implicit conversion from T to Nullable <T>. Nullable <T> can be explicitly converted to T.
1 Nullable <long> nL = 7; 2 long L = (long) nL; 3 4 // an error is reported, which must be explicitly converted to 5 // long ll = nL;
Speaking of the first line of code above, it reminds me of the replication constructor in C ++ or a parameter constructor. Let's take a look at it, C # should also be implemented in C ++.
6. nullable <T> can be understood as implicit conversion from T to Nullable <T> as packing, while Nullable <T> can be explicitly converted to T as unpacking.
7. The syntax sugar can be used to reduce the input of code and use a symbol "? "
1 int? intNull = null;
8. You can use null for comparison.
9. can be null type can participate in the operator, which will contain some type conversion, the experience is used to find the same as the general type, and because the null type can be expressed by null, you can participate in logical operators (that is, those that return true and false ). Of course, it can also be thought that the as operator is also normal and available.
Please make an axe.