In C #?? And? What is the meaning of the distinction?

Source: Internet
Author: User

In C #?? What's the meaning of the distinction?


1. Nullable type modifier (? ):
A reference type can use a null reference to represent a value that does not exist, and a value type usually cannot be represented as empty.
For example: string str=null; is correct, int i=null; the compiler will error.
To make a value type nullable, you can use a nullable type, which is the nullable type modifier "? "To indicate that the representation is" T? "
for example: Int? Represents a nullable shape, DateTime? Represents a time that can be empty.
T? is actually an abbreviated form of system.nullable (generic structure), which means when you use T? When the compiler compiles the T? Compiled into a system.nullable form.
For example: int, after compiling is the form of system.nullable.

2. Ternary (operator) expression (?:) :
For example: X?y:z indicates that if the expression x is true, then Y is returned, and if X is False, Z is returned, which is a simple form of omitting if{}else{}.

3. Empty merge operator (??) :
used to define the default values for nullable types and reference types. If the left operand of this operator is not NULL, this operator returns the left operand, otherwise the right operand is returned.
For example: a?? b When a is null, returns B,A if it is not null.
An empty merge operator is a right-associative operator, which is a combination of right-to-left operations. For example, "a??" B?? C "In the form of" a?? (b?? c) "calculation.

In C #?? And? What is the meaning of the distinction?

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.