c# - Variable declaration differences var with cast or -


this question has answer here:

is there background difference between 2 declarations:

var x = (string)null; 

and

string x = null; 

will runtime treat declarations different ways? compiler produce same il?

yes, produces same il:

void main() {     var x = (string)null;     string y = null; } 

produces (with optimizations turned off):

il_0000:  nop          il_0001:  ldnull       il_0002:  stloc.0     // x il_0003:  ldnull       il_0004:  stloc.1     // y il_0005:  ret         

from compilers perspective, assigning null string variable.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -