日期:2014-05-17  浏览次数:20789 次

关于IL语言的一个问题
以下的代码:

 //判断字符串是否为空      
            string str1 = "MyWord";       
            if (str1 == "");       
            Console.Read();  

在用ildasm.exe打开后生成的IL语言如下:

.method private hidebysig static void  Main(string[] args) cil managed
{
  .entrypoint
  // 代码大小       32 (0x20)
  .maxstack  2
  .locals init ([0] string str1,
           [1] bool CS$4$0000)
  IL_0000:  nop
  IL_0001:  ldstr      "MyWord"
  IL_0006:  stloc.0
  IL_0007:  ldloc.0
  IL_0008:  ldstr      ""
  IL_000d:  call       bool [mscorlib]System.String::op_Equality(string,
                                                                 string)
  IL_0012:  ldc.i4.0   // 这句话是什么意思呢?
  IL_0013:  ceq
  IL_0015:  stloc.1
  IL_0016:  ldloc.1
  IL_0017:  brtrue.s   IL_0019
  IL_0019:  call       int32 [mscorlib]System.Console::Read()
  IL_001e:  pop
  IL_001f:  ret
} // end of method Program::Main


关于IL_0012一行 我不明白为什么有这么一句,有知道的么?
cil

------解决方案--------------------
将整数值0作为int32加载到计算堆栈上