C # Empty type Learning

Source: Internet
Author: User

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;

 

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.