Possible Duplicate:
Nullable types and the ternary operator. Why won’t this work?
for example:
int? taxid;
if (ddlProductTax.SelectedValue == "") {
taxid = null; }
else {
taxid = Convert.ToInt32(ddlProductTax.SelectedValue);
} //Correct
But
int? taxid;
taxid = (ddlProductTax.SelectedValue == "" ? null : Convert.ToInt32(ddlProductTax.SelectedValue)); //Error
It error say and int32 cannot implicit convert.
The ( ? truepart : falsepart); is not short of (if ..else..) ?
The last two operands of the ternary operator should both yield the same type.
Cast either side to
int?:You can see the exact behavior in the specification: