, . , null LookupCode<T> (- , ), ; .
void Main()
{
byte? reviewMonth = null;
string result = reviewMonth == null
? null
: new LookupCode<object> { Description = "Hi!" };
result.Dump();
}
class LookupCode<T>
{
public string Description { get; set; }
public static implicit operator string(LookupCode<T> code)
{
if (code != null) return code.Description;
throw new InvalidOperationException();
}
}
, - null ( a default(LookupCode<object>)) string, . .
, , :
string result = reviewMonth == null
? default(LookupCode<object>)
: "Does this get evaluated?".Dump();
- , . , , : ; . :
ldnull
call LookupCode`1.op_Implicit
:)
: null, default(string). R # - (string)null null , R # .
, # (14.13 - ):
?: .
X Y . ,
- X Y , .
- , (§13.1) X Y, Y X, Y .
- , (§13.1) Y X, X Y, X .
- , .
LookupCode<T> string, , LookupCode<T> string. , , , LHS :
string result = ...
var result = ...