IL_0005: stloc.1
IL_0006: nop
IL_0007: ldloc.1
IL_0008: ldstr "hello world"
IL_000d: stfld string ThreadWithParameters.Program/'<>c__DisplayClass1'::hello
IL_0012: ldloc.1
IL_0013: ldftn instance void ThreadWithParameters.Program/'<>c__DisplayClass1'::'<Main>b__0'()
IL_0019: newobj instance void [mscorlib]System.Threading.ThreadStart::.ctor(object, native int)
IL_001e: newobj instance void [mscorlib]System.Threading.Thread::.ctor(class [mscorlib]System.Threading.ThreadStart)
IL_0023: stloc.0
IL_0024: ldloc.0
IL_0025: callvirt instance void [mscorlib]System.Threading.Thread::Start()
IL_002a: nop
IL_002b: call int32 [mscorlib]System.Console::Read()
IL_0030: pop
IL_0031: nop
IL_0032: ret
} // end of method Program::Main
在看看第二种方式的IL代码:
-
.method private hidebysig static void Main(string[] args) cil managed
{
-
.entrypoint
// 代码大小 44 (0x2c)
-
.maxstack 3
.locals init ([0] class ThreadWithParameters.MyThread myThread,
-
[1] class [mscorlib]System.Threading.Thread thread)
IL_0000: nop
-
IL_0001: ldstr "hello world"
IL_0006: newobj instance void ThreadWithParameters.MyThread::.ctor(string)