C# Nullable Type question

Posted by TatMing on Stack Overflow See other posts from Stack Overflow or by TatMing
Published on 2010-06-11T07:05:48Z Indexed on 2010/06/11 7:12 UTC
Read the original article Hit count: 195

Filed under:

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..) ?

© Stack Overflow or respective owner

Related posts about c#