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

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -