Possible Duplicate:
Conditional operator cannot cast implicitly?
When writing a statement using the conditional operator, if the either of the expressions are numeric values they are always interpreted as int
type. This makes a cast necessary to assign a short
variable using this operator.
bool isTrue = true;
int intVal = isTrue ? 1 : 2;
short shortVal = isTrue ? 1 : 2; // Compile error: Cannot implicitly convert type 'int' to 'short'.
Shouldn't the compiler be able to know that both values are valid short
values just as it would in a typical assignment statement(short shortVal = 1;
)?