I can write
if(Model.DecisionReason != null && Model.DecisionReason.Length > 35)
return Model.DecisionReason.Substring(0, 32) + "...";
else
return Model.DecisionReason;
and comparison &&in ifwill be a short circuit, preventing an exception if Model.DecisionReasonnull. However, if I write
return (Model.DecisionReason != null && Model.DecisionReason.Length > 35) ?
Model.DecisionReason.Substring(0, 32) + "..." :
Model.DecisionReason;
There is no short circuit, and I got the exception. Is there a way to do this for a short circuit, or am I forced to either wrap the length comparison in the test iffor tees or sockets (not the most read)?
source
share