C # Syntax: Question mark "?" Use of Data Types

Source: Internet
Author: User

The question mark represents a weak type in C. Nullable is a new technique provided in. NET 2.0 to indicate whether a value type can be empty.

For a type, if you can either assign a value to it or assign a null reference to it (indicating that there is no value), we can say that this type can be empty.

The following describes how to use question marks:

A. The variable definition contains a question mark, which indicates that the data type is nullable. When you set an initial value for a variable, assign null to the variable (INT type) instead of 0!

Example: Int? X = 125 is equivalent to nullable <int> X = new nullable <int> (125 );

B. The variable definition contains two question marks, which are used to determine and assign values. First, it determines whether the current variable is null. If yes, it can be assigned a new value. Otherwise, it will be skipped! What does it mean to take the assigned value ?? On the left, if the left is null, the assigned value is used ?? On the right.

Example: Page ?? 0 indicates that when page is null, the value on the right is 0.

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.