我不知道为什么,但我观察了标准 c# 编译器 (VS2015) 生成的 IL,它在发布模式下明显没有优化。
我测试的代码非常简单:
static void Main(string[] args)
{
int count = 25 + 7/3;
count += 100;
Console.WriteLine("{0}", count);
}
Run Code Online (Sandbox Code Playgroud)
调试模式下的 IL 输出为:
// [12 9 - 12 10]
IL_0000: nop
// [34 13 - 34 34]
IL_0001: ldc.i4.s 27 // 0x1b
IL_0003: stloc.0 // count
// [35 13 - 35 26]
IL_0004: ldloc.0 // count
IL_0005: ldc.i4.s 100 // 0x64
IL_0007: add
IL_0008: stloc.0 // count
// [36 13 - 36 45]
IL_0009: ldstr "{0}" …Run Code Online (Sandbox Code Playgroud)