2009-08-16 64 views

回答

8

簡短的回答返回值:一旦

龍答:

的代碼被編譯成以下的IL。您可以通過編譯C#文件,然後在ILDASM(與Visual Studio一起分發)或.NET Reflector(可以顯示多語言反彙編代碼並具有詳細說明的IL說明的工具提示)中打開它來自己嘗試。

L_0008: ldloc.0 
L_0009: callvirt instance string [mscorlib]System.String::ToLowerInvariant() 
L_000e: stloc.2 
L_000f: ldc.i4.0 
L_0010: stloc.3 
L_0011: br.s L_0021 
L_0013: ldloc.2 
L_0014: ldloc.3 
L_0015: callvirt instance char [mscorlib]System.String::get_Chars(int32) 
L_001a: stloc.1 
L_001b: nop 
L_001c: nop 
L_001d: ldloc.3 
L_001e: ldc.i4.1 
L_001f: add 
L_0020: stloc.3 
L_0021: ldloc.3 
L_0022: ldloc.2 
L_0023: callvirt instance int32 [mscorlib]System.String::get_Length() 
L_0028: clt 
L_002a: stloc.s flag 
L_002c: ldloc.s flag 
L_002e: brtrue.s L_0013 

實際循環條件是在檢查線以L_0021 L_002c再有在行L_002e如果不是所有字符都尚未處理時執行的跳躍。請注意,它跳轉到ToLowerInvariant調用之後的L_0013。

2

一次......然後它遍歷每個獲得由呼叫