In C #, the two question marks are used to determine ?? Is the object on the left null? If not null ?? The object on the left. If it is null, use ?? Object on the right.
For example, a = B ?? C. If B is null, A = C. If B is not null, A = B.
The following sectionCodeThese two cases are demonstrated:
01 |
Static Void Main ( String [] ARGs) |
08 |
Private Static Void Newfuck () |
11 |
Console. writeline (fuck ?? "Fuck not found ." ); |
14 |
Private Static Void Shit () |
17 |
String B = ( String ) Shit ?? "Shit not found ." ; |
18 |
Console. writeline (B ); |
The execution result is as follows:
Obviously, this operator similar to the three-object expression can be used to install B in front of the sister. Let's look at an intuitive example:
01 |
// Literature and art fuck |
02 |
Private Static Void Newfuck () |
05 |
Console. writeline (fuck ?? "Fuck not found ." ); |
09 |
Private Static Void Fuck () |
12 |
String S = fuck! = Null ? Fuck: "Fuck not found ." ; |
13 |
Console. writeline (s ); |
17 |
Private Static Void Sbfuck () |
28 |
S = "Fuck not found ." ; |
30 |
Console. writeline (s ); |
The three methods are the same in the result and will output the fuck on the screen. Of course, writing an example is only demo-level. We use it in actual programming ?? Operators are often more useful and can save a lot of trouble. For example, when processing the querystring page:
01 |
// The processing parameters are as follows: |
02 |
String TMD = string. empty; |
03 |
If (Request [ "Select" ]! = Null ) |
05 |
TMD = request [ "Select" ]; |
13 |
String Tmd1 = request [ "Select" ] ??? "All" ; |
How is it? Do you think it is amazing. This can also be done for sessions or something. By the way, the processing parameters in the actual project are more complex than this one. It usually includes operations such as type conversion. We recommend that you use the as operator for type conversion.