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:? ,??