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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -