08.c# system.nulable<t> and null reference operators (four chapters 4.2-4.4)

Source: Internet
Author: User

Look at these 3 bars, found that the author is too detailed, put a normal use of the usage is too god-dense, do not know that they do not understand the author's painstaking, or the author's intention, here to everyone is simple to say, too deep sincerity can not go on.

1. The core part of the nullable type is System.nullable<t>, which, in addition to this, has a tool method provided by the static class System.Nullable.

2.nullable<t> is a generic type, and the type parameter T is a value type constraint.

The type of 3.T is called the underlying type of a nullable type.

4.nullable<t> has two constructors, one for creating an instance with no value, one for receiving an instance of T as a value

1 nullable<intnew nullable<int>(); 2 nullable<intnew nullable<int> (1);

5. The framework provides two transformations, and the implicit conversion of T to nullable<t>,nullable<t> can be explicitly converted to T

1 nullable<long7; 2 Long L = (long) NL; 3 4 // error, requires explicit conversion 5 // long ll = NL;

Speaking of the first line of code, let me think of C + + in the Copy construction method, or a parameter of the construction method, you can go to see, C # should also be implemented in C + +.

6.nullable<t> Boxing and unpacking, do not know whether it is possible to understand the implicit conversion of T to nullable<t> is boxed,nullable<t> can be explicitly converted to T is unboxing.

7. You can use the syntax sugar, reduce the input of the code, use a symbol "?"

1 int null;

8. You can use NULL for comparison, as above

9. Nullable types can participate in operators, which include some type conversions, which are used to discover the same type as normal, and because nullable types can use null representations, they can participate in logical operators (that is, return true and false ones). It is also possible to think of the operator as as normal and usable.

Please treatise.

Reference page:hTTP://QINgQINgQuege.CNbLogs.Com/P/5933752.hTmL

08.c# system.nulable<t> and null reference operators (four chapters 4.2-4.4)

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.