[C #] implementation principle of the void type,

Source: Internet
Author: User

[C #] implementation principle of the void type,

Int? Is a null value type. Only one value greater than int Is null.

Thoughts:

In the same memory space, how can one more value be implemented? All are 4 bytes, 32 bits, int? Depends on what has a null value.

 

Found:

Analyze the memory to see how it is implemented.

When int I = max; int? J = max; the value of the next 4-byte address of j is the same as that of I.

 

Assign a null value to j. The original value of 1 is 0.

 

Assign a value of 0 to j. The original value of 0 is 1. j, 1. j, or 1. j, respectively.

 

Result:

Determine int? Originally 8 bytes. When the first 4 bytes are 1, it is not null. The last four bytes are exactly the same as the normal int type.

 

Int? Bool? This can be empty typeMeaning?

1. to match the corresponding types in the database.

2. Some controls have three states. Such as: checkbox, selected, unselected, not all selected

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.