From:http://www.cnblogs.com/zfanlong1314/archive/2012/02/26/2390456.html
(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 non-assignable elements, null is assigned to the numeric type or Boolean and The date type feature is particularly useful. true or fal SE, or it may be undefined. " For example, a Boolean field in a database can store the value true or false, or the field may not be defined.
(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
<summary>
Gets a Single instance
</summary>
public static Log Loginstance
{
Get
{
Return _log?? (_log = new log ()); If the left operand of this operator is not NULL, this operator returns the left operand, otherwise the right operand is returned.
}
}
A question mark (?) in C # syntax. ) and two question marks (??) What does the operator mean?