它将在编译时预先计算任何常量表达式,包括字符串连接.没有const
它,它将被遗弃.
你的第一个例子编译成这个IL:
.maxstack 2 .locals init ([0] int32, [1] int32) ldc.i4.1 //load 1 stloc.0 //store in 1st local variable ldc.i4.5 //load 5 ldloc.0 //load 1st variable mul // 1 * 5 stloc.1 // store in 2nd local variable
第二个例子编译为:
.maxstack 1 .locals init ( [0] int32 ) ldc.i4.5 //load 5 stloc.0 //store in local variable