(1), C # syntax of a question mark (?) Operator refers to a nullable type.
The explanation above MSDN:
null to numeric and Boolean types was especially useful when you were dealing with databases an d Other data types, that contain elements, is not being assigned a value. " > when working with databases and other data types that contain elements that are not assignable, null assigned to numeric type or Boolean The and date type features are particularly useful. true or fal SE, or it may be undefined. " For example, a Boolean field in a database can store a value of true or false, or, The field can also be undefined.
(2), C # syntax, two question marks (??) operator refers to the null merge operator , and the merge operator defines a preset value for the type conversion, in case the value of the nullable type is null.
The explanation above MSDN:
?? Operators are called null Merge operators, which define the default values for types and reference types that can be null values. If the left operand of this operator is not NULL, this operator returns the left operand (the left expression) or, if the left operand is null, returns the right operand (the right-hand expression).
C # Code:
Int? x = null; To define a nullable type variable
Int? y = x?? 1000; //using the merge operator, when the variable x is null, the preset is assigned a value of 1000
Console.WriteLine (Y.tostring ()); //1000
A question mark (?) in C # syntax. ) with two question marks (??). ) What's the difference?