public void OutsideLoop()
{
Button button;
for (long l=0;l<1000;l++)
button=new Button();
}
public void InsideLoop()
{
for (long l=0;l<1000;l++)
{
Button button=new Button();
}
}
IL-koden som genereras :
.method public hidebysig instance void OutsideLoop() cil managed
{
// Code size 26 (0x1a)
.maxstack 2
.locals init ([0] int64 l,
[1] class [System.Windows.Forms]System.Windows.Forms.Button button)
IL_0000: ldc.i4.0
IL_0001: conv.i8
IL_0002: stloc.0
IL_0003: br.s IL_0010
IL_0005: newobj instance void [System.Windows.Forms]System.Windows.Forms.Button::.ctor()
IL_000a: stloc.1
IL_000b: ldloc.0
IL_000c: ldc.i4.1
IL_000d: conv.i8
IL_000e: add
IL_000f: stloc.0
IL_0010: ldloc.0
IL_0011: ldc.i4 0x3e8
IL_0016: conv.i8
IL_0017: blt.s IL_0005
IL_0019: ret
} // end of method Form1::OutsideLoop
.method public hidebysig instance void InsideLoop() cil managed
{
// Code size 26 (0x1a)
.maxstack 2
.locals init ([0] class [System.Windows.Forms]System.Windows.Forms.Button button,
[1] int64 l)
IL_0000: ldc.i4.0
IL_0001: conv.i8
IL_0002: stloc.1
IL_0003: br.s IL_0010
IL_0005: newobj instance void [System.Windows.Forms]System.Windows.Forms.Button::.ctor()
IL_000a: stloc.0
IL_000b: ldloc.1
IL_000c: ldc.i4.1
IL_000d: conv.i8
IL_000e: add
IL_000f: stloc.1
IL_0010: ldloc.1
IL_0011: ldc.i4 0x3e8
IL_0016: conv.i8
IL_0017: blt.s IL_0005
IL_0019: ret
} // end of method Form1::InsideLoop