I am trying to assign 0 to a short variable from a condition and it throws compile time error that
Cannot implicitly convert type 'int' to 'short'. An explicit conversion exists (are you missing a cast?)
Refer below screenshot. The salesLineInput.Discount is a short
and SalesLineEntity.Discount is a Nullable<double>
:
This is some other code I tried (not the same as in the screenshot):
if(SalesLineEntity.Discount.HasValue)
salesLineInput.Discount = (short)(SalesLineEntity.Discount * 100);
else
salesLineInput.Discount = 0;
Why does the if
work, but the ternary doesn't?