早上好,下午好,还是晚上好,
MSIL 或 JIT 编译器会替换像 1 << 5
这样的东西吗?或 1 << 31
在带有 32
的代码中和 2147483648
,或者他们会等待方法执行以“及时”评估这些常量,因为它们涉及其他方法(运算符)?
非常感谢。
最佳答案
试一试。
下面的代码
static void Main ( string[] args )
{
Console.WriteLine ( 1 << 4 );
}
编译为
IL_0000: nop
IL_0001: ldc.i4.s 16
IL_0003: call void [mscorlib]System.Console::WriteLine(int32)
IL_0008: nop
IL_0009: ret
它只是加载常量 16 并将其传递给 WriteLine。
关于c# - C# 中的计算常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5379369/