C # operator:? ,??

Source: Internet
Author: User
Tags microsoft help

Refer to Microsoft Help

1? a null-value conditional operator that tests for the presence of NULL before performing a member access ( ?. ) or index ( ?[ ) operation.

1 // ? null-value condition operator 2 string NULL ; 3 Console.WriteLine (str?. length);//And the following if statement is equivalent, that is, the first to determine whether STR is NULL, if the null value is not calculated downward, if STR is not NULL, the length of the output str string.  4if (str =null)5{6      Console.WriteLine (str. Length); 7 }8 console.readkey ();

The 2 ?? operator is called a null merge operator. if the left operand of this operator is not NULL, this operator returns the left operand, otherwise the right operand is returned.

1 //?? null merge Operator2  stringstr =NULL;3  stringstr2;4str2 = str??"www";//And the following if statement is equivalent, if STR is not empty, then the STR is assigned to STR2, otherwise "www" is assigned to STR2.5  if(str! =NULL)6      {7STR2 =str;8      }9  ElseTen    { OneSTR2 ="www"; A}

C # operator:? ,??

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.