08. C # System. Nulable & lt; T & gt; and null reference operators (Chapter 4 4.2-4.4 ),

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.