c# - Variable declaration differences var with cast or -
this question has answer here:
- initializing 'var' null 2 answers
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
Post a Comment