For comparison, and Foreach

  C # code: 
  Public int LoopTest () 
  ( 
  Int s = 0; 

  Int [] array 2,3,4,5,6,7,8,9 = (); 

  For (int k = 0; k <= 7; k + +) 
  ( 
  S + = array [k]; 
  ) 

  Foreach (int a in array) 
  ( 
  S + = a; 
  ) 

  Return s; 

  ) 

  IL code: 
  . Method public hidebysig instance int32 LoopTest () cil managed 
  ( 
  / / Code size 78 (0×4e) 
  . Maxstack 3 
  . Locals init ([0] int32 s, 
  [1] [] int32 'array' 
  [2] int32 k, 
  [3] int32 a, 
  [4] int32 CS $ 00000003 $ 00000000, 
  [5] [] CS int32 $ 00000007 $ 00000001, 
  [6] int32 CS $ 00000008 $ 00000002) 
  IL_0000: ldc.i4.0 
  IL_0001: stloc.0 
  IL_0002: ldc.i4.8 
  IL_0003: newarr [mscorlib] System.Int32 
  IL_0008: dup 
  IL_0009: ldtoken field valuetype '<PrivateImplementationDetails>'/'$$ struct0×6000002-1' '<PrivateImplementationDetails>'::'$$ method0×6000002-1' 
  IL_000e: call void System.Runtime.CompilerServices.RuntimeHelpers [mscorlib]:: InitializeArray (class [mscorlib] System.Array, 
  Valuetype [mscorlib] System.RuntimeFieldHandle) 
  IL_0013: stloc.1 
  IL_0014: ldc.i4.0 
  IL_0015: stloc.2 
  IL_0016: br.s IL_0022 / / place for the beginning of 
  IL_0018: ldloc.0 
  IL_0019: ldloc.1 
  IL_001a: ldloc.2 
  IL_001b: ldelem.i4 
  IL_001c: add 
  IL_001d: stloc.0 
  IL_001e: ldloc.2 
  IL_001f: ldc.i4.1 
  IL_0020: add 
  IL_0021: stloc.2 
  IL_0022: ldloc.2 
  IL_0023: ldc.i4.7 
  IL_0024: ble.s IL_0018 / / for the end of the local 
  IL_0026: ldloc.1 / / foreach from here 
  IL_0027: stloc.s CS $ 00000007 $ 00000001 
  IL_0029: ldc.i4.0 
  IL_002a: stloc.s CS $ 00000008 $ 00000002 
  IL_002c: br.s IL_003e 
  IL_002e: ldloc.s CS $ 00000007 $ 00000001 
  IL_0030: ldloc.s CS $ 00000008 $ 00000002 
  IL_0032: ldelem.i4 
  IL_0033: stloc.3 
  IL_0034: ldloc.0 
  IL_0035: ldloc.3 
  IL_0036: add 
  IL_0037: stloc.0 
  IL_0038: ldloc.s CS $ 00000008 $ 00000002 
  IL_003a: ldc.i4.1 
  IL_003b: add 
  IL_003c: stloc.s CS $ 00000008 $ 00000002 
  IL_003e: ldloc.s CS $ 00000008 $ 00000002 
  IL_0040: ldloc.s CS $ 00000007 $ 00000001 
  IL_0042: ldlen 
  IL_0043: conv.i4 
  IL_0044: blt.s IL_002e / / foreach end of the local 
  IL_0046: ldloc.0 
  IL_0047: stloc.s CS $ 00000003 $ 00000000 / / This is an automatically generated variables, preservation return value, did not void 
  IL_0049: br.s IL_004b 
  IL_004b: ldloc.s CS $ 00000003 $ 00000000 
  IL_004d: ret 
  ) / / End of method Class1:: LoopTest 

Bookmark it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Google
  • DotNetKicks
  • DZone
  • Furl
  • Netvouz

Releated Articles

  • Popuklar Articles

0 Comments to “For comparison, and Foreach”

No Comments. Send your comment.

Leave a Reply

You must be logged in to post a comment.