变量放在循环体内还是循环体外

.method private hidebysig static void  Main(string[] args) cil managed
{
  .entrypoint                    //程序入口
  // 代码大小       31 (0x1f)
  .maxstack  2                    //定义函数代码所用堆栈的最大深度,也指Evaluation Stackk中最多能同时存在3个值
  .locals init ([0] int32 i)    //定义 int 类型参数 V_0 (此时已经把V_0存入了Call Stack中的Record Frame中)
  IL_0000:  ldc.i4.0            //加载变量"i"的值 (压入Evaluation Stack中)
  IL_0001:  stloc.0                //从栈中把"i"的值弹出并赋值给Record Frame中第0个位置(V_0)
  IL_0002:  br.s       IL_0013    //无条件地将控制转移到目标指令(短格式)
  IL_0004:  newobj     instance void ConsoleApp1.TempClass::.ctor()  //创建一个值类型的新对象或新实例,并将对象引用(O 类型)推送到计算堆栈上
  IL_0009:  ldloc.0                //取Record Frame中位置为0的元素(V_0)的值("i"的值)并压入栈中
  IL_000a:  callvirt   instance void ConsoleApp1.TempClass::test(int32)
  IL_000f:  ldloc.0                //取Record Frame中位置为0的元素(V_0)的值("i"的值)并压入栈中
  IL_0010:  ldc.i4.1            //加载变量"tempClass"的值 (压入Evaluation Stack中)
  IL_0011:  add                    //做加法操作
  IL_0012:  stloc.0                //从栈中把 "i"的值弹出并赋值给Record Frame中第0个位置(V_0)
  IL_0013:  ldloc.0                //取Record Frame中位置为0的元素(V_0)的值("i"的值)并压入栈中
  IL_0014:  ldc.i4.s   10
  IL_0016:  blt.s      IL_0004    //如果第一个值小于第二个值,则将控制转移到目标指令(短格式)
  IL_0018:  call       string [mscorlib]System.Console::ReadLine()
  IL_001d:  pop
  IL_001e:  ret
} // end of method Program::Main
.method private hidebysig static void  Main(string[] args) cil managed
{
  .entrypoint                    //程序入口
  // 代码大小       33 (0x21)
  .maxstack  2                    //定义函数代码所用堆栈的最大深度,也指Evaluation Stackk中最多能同时存在3个值
  .locals init ([0] class ConsoleApp3.TempClass tempClass,
           [1] int32 i)                //定义class类型参数 V_0,int类型参数 V_1 (此时已经把V_0,V_1存入了Call Stack中的Record Frame中)
  IL_0000:  newobj     instance void ConsoleApp3.TempClass::.ctor()    //创建一个值类型的新对象或新实例,并将对象引用(O 类型)推送到计算堆栈上
  IL_0005:  stloc.0                //从栈中把"tempClass"的值弹出并赋值给Record Frame中第0个位置(V_0)
  IL_0006:  ldc.i4.0            //加载变量"tempClass"的值 (压入Evaluation Stack中)
  IL_0007:  stloc.1                //从栈中把"i"的值弹出并赋值给Record Frame中第0个位置(V_0)
  IL_0008:  br.s       IL_0015    //无条件地将控制转移到目标指令(短格式)
  IL_000a:  ldloc.0                //取Record Frame中位置为0的元素(V_0)的值("tempClass"的值)并压入栈中
  IL_000b:  ldloc.1                //取Record Frame中位置为0的元素(V_1)的值("i"的值)并压入栈中
  IL_000c:  callvirt   instance void ConsoleApp3.TempClass::test(int32)
  IL_0011:  ldloc.1                //取Record Frame中位置为0的元素(V_1)的值("i"的值)并压入栈中
  IL_0012:  ldc.i4.1            //加载变量"i"的值 (压入Evaluation Stack中)
  IL_0013:  add                    //做加法操作
  IL_0014:  stloc.1                //从栈中把 "i"的值弹出并赋值给Record Frame中第0个位置(V_0)
  IL_0015:  ldloc.1                //取Record Frame中位置为0的元素(V_0)的值("i"的值)并压入栈中
  IL_0016:  ldc.i4.s   10
  IL_0018:  blt.s      IL_000a    //如果第一个值小于第二个值,则将控制转移到目标指令(短格式)
  IL_001a:  call       string [mscorlib]System.Console::ReadLine()
  IL_001f:  pop
  IL_0020:  ret
} // end of method Program::Main

 

posted @ 2017-11-09 14:24  菡萏No.1  阅读(314)  评论(0)    收藏  举报