Question mark (?) in C ??

Source: Internet
Author: User

1. Use Cases

2. ReferenceArticleAnd examplesCodeDownload

 

1. Use Cases

Msdn:It returns the left-hand operand if it is not null; otherwise it returns the right operand. if the left value is not blank, the left value is returned. Otherwise, the right value is returned. The following is a test example:

class nullcoalesce
{< br> static int ? getnullableint ()
{< br> return null ;< BR >}

static string getstringvalue ()
{< br> return null ;
}

static void main ()
{< br> /// ?? Operator example.
int ? x = null ;

//Y = x, unless X is null, in which case y =-1.
IntY=X?? -1;

// Assign I to return value of method, unless
// Return Value is null, in which case assign
// Default Value of int to I.
Int I = Getnullableint () ??   Default ( Int );

String S = Getstringvalue ();
// ?? Also works with reference types.
// Display contents of S, unless s is null,
// In which case display "unspecified ".
Console. writeline (S ??   " Unspecified " );
}
}


 

2. Download reference articles and sample code

References:

Http://msdn.microsoft.com/en-us/library/ms173224.aspx

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.