, , , , , .
:
string temp = data.val != null ? data.val.ToLower() : null;
if ("x".Equals(temp)) { }
.
:
bool? temp = data.val != null ? data.val.ToLower().Equals("x") : null;
if (temp) { } 
This may be less obvious, but the operator data.val?.ToLower().Equals("x")will return nullif data.valis nullotherwise it will return the result data.val.ToLower().Equals("x"). Since the operator can return nullor bool, the type of the whole operator bool?, but you cannot directly use bool?in if.
As others have pointed out, converting bool?to boolwill fix your problem. One way to do this is to use GetValueOrDefault():
if (data.val?.ToLower().Equals("x").GetValueOrDefault()) { }
 source
share