Re: [RESOLVED] Passing Nulls
Wait, is this resolved?
The type of the parameter that the expression is heading for isn't considered in resolving the type of the expression itself.
The type of a ternary expression is derived from the types of the two return values. The first (null) is of type void (well, that's not exactly a type, but you know what I mean, right?) and the second (Convert.ToInt16(drpStatus.SelectedItem.Value)) is of type int.
int and null are not comparable, therefore that expression is not legal. You need to give the compiler a hint, by casting the null to an 'int?'.
That way you're comparing an 'int?' to an int, which have a common type of 'int?'
Re: [RESOLVED] Passing Nulls
Hi,
Although I didn't post my resolution, I needed to cast with Null.
(Int16?)null
So My complete test became.
Code:
drpStatus.SelectedItem.Value == "" ? (Int16?)null : Convert.ToInt16(drpStatus.SelectedItem.Value)