首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

关于IL语言的一个有关问题

2013-01-23 
关于IL语言的一个问题以下的代码: //判断字符串是否为空string str1 MyWordif (str1 )Console.

关于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加载到计算堆栈上

热点排行