c# - cast short to int in if block -
i have following code:
int16 myshortint; myshortint = condition ? 1 :2;
this code results in compiler error:
cannot implicity convert type 'int' 'short'
if write condition in expanded format there no compiler error:
if(condition) { myshortint = 1; } else { myshortint = 2; }
why compiler error ?
when code being compiled, looks this:
for:
int16 myshortint; myshortint = condition ? 1 :2;
it looks somthing
int16 myshortint; var value = condition ? 1 :2; //notice interperted integer. myshortint = value ;
while for:
if(condition) { myshortint = 1; } else { myshortint = 2; }
there no stage in between interperate value int, , literal being treated int16.
Comments
Post a Comment