C # A question mark (?) in the syntax (?) And two question marks (??) What does the operator mean?

Source: Internet
Author: User

(1), C # each question mark (?) in the syntax (?) Operator refers:It can be a null type.

 The above description on msdn:

When processing the data type of the database and other elements that contain non-assigned valuesNullAssignedValue TypeOrBooleanAndDate typeIs particularly useful. For example, a Boolean field in a database can store values.TrueOrFalseOr, this field can be undefined.

 

(2), C # Two question marks (?) in the syntax (??) Operator refersNull merge OperatorThe merge operator defines a default value for type conversion to prevent null values of the null type.

The above description on msdn:

??An operator is a null merge operator that defines the types that can be null values and the default values of reference types.If the left operand of this operator is not null, this operator returns the left operand (left expression); otherwise, when the left operand is null, the right operand (right expression) is returned ).

C # code:

Int? X =Null;// Define a variable of the null type
Int? Y = x ?? 1000;// Use the merge operator. If the variable X is null, the default value is 1000.

Console. writeline (Y. tostring ());// 1000

 

/// <Summary>
/// Gets a single instance
/// </Summary>
Public static log loginstance
{
Get

{

Return _ log ?? (_ Log = new log (); // If the left operand of this operator is not null, this operator returns the left operand; otherwise, the right operand is returned.
}
}

 

 

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.