Last active
August 29, 2015 13:59
-
-
Save kimsk/10743576 to your computer and use it in GitHub Desktop.
foreach or IEnumerator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var array = new int[1000000]; | |
foreach (var i in array){} | |
var enumerator = array.GetEnumerator(); | |
while (enumerator.MoveNext()){} | |
var lines = System.IO.File.ReadLines("c:\temp"); | |
foreach (var line in lines){} | |
var fileEnum = lines.GetEnumerator(); | |
while (fileEnum.MoveNext()) { } | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using Telerik JustDecompile | |
private static void Main(string[] args) | |
{ | |
int[] array = new int[1000000]; | |
int[] numArray = array; | |
for (int i = 0; i < (int)numArray.Length; i++) | |
{ | |
int num = numArray[i]; | |
} | |
IEnumerator enumerator = array.GetEnumerator(); | |
while (enumerator.MoveNext()){} | |
IEnumerable<string> lines = File.ReadLines("c:\temp"); | |
foreach (string str in lines){} | |
IEnumerator<string> fileEnum = lines.GetEnumerator(); | |
while (fileEnum.MoveNext()){} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.method private hidebysig static void Main ( | |
string[] args | |
) cil managed | |
{ | |
.entrypoint | |
.locals init ( | |
[0] int32[] 'array', | |
[1] class [mscorlib]System.Collections.IEnumerator enumerator, | |
[2] class [mscorlib]System.Collections.Generic.IEnumerable`1<string> lines, | |
[3] class [mscorlib]System.Collections.Generic.IEnumerator`1<string> fileEnum, | |
[4] int32[] CS$6$0000, | |
[5] int32 CS$7$0001, | |
[6] class [mscorlib]System.Collections.Generic.IEnumerator`1<string> CS$5$0002 | |
) | |
IL_0000: ldc.i4 1000000 | |
IL_0005: newarr [mscorlib]System.Int32 | |
IL_000a: stloc.0 | |
IL_000b: ldloc.0 | |
IL_000c: stloc.s CS$6$0000 | |
IL_000e: ldc.i4.0 | |
IL_000f: stloc.s CS$7$0001 | |
IL_0011: br.s IL_001f | |
.loop | |
{ | |
IL_0013: ldloc.s CS$6$0000 | |
IL_0015: ldloc.s CS$7$0001 | |
IL_0017: ldelem.i4 | |
IL_0018: pop | |
IL_0019: ldloc.s CS$7$0001 | |
IL_001b: ldc.i4.1 | |
IL_001c: add | |
IL_001d: stloc.s CS$7$0001 | |
IL_001f: ldloc.s CS$7$0001 | |
IL_0021: ldloc.s CS$6$0000 | |
IL_0023: ldlen | |
IL_0024: conv.i4 | |
IL_0025: blt.s IL_0013 | |
} | |
IL_0027: ldloc.0 | |
IL_0028: callvirt instance class [mscorlib]System.Collections.IEnumerator [mscorlib]System.Array::GetEnumerator() | |
IL_002d: stloc.1 | |
.loop | |
{ | |
IL_002e: ldloc.1 | |
IL_002f: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext() | |
IL_0034: brtrue.s IL_002e | |
} | |
IL_0036: ldstr "c:\temp" | |
IL_003b: call class [mscorlib]System.Collections.Generic.IEnumerable`1<string> [mscorlib]System.IO.File::ReadLines(string) | |
IL_0040: stloc.2 | |
IL_0041: ldloc.2 | |
IL_0042: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1<string> class [mscorlib]System.Collections.Generic.IEnumerable`1<string>::GetEnumerator() | |
IL_0047: stloc.s CS$5$0002 | |
.try | |
{ | |
IL_0049: br.s IL_0053 | |
.loop | |
{ | |
IL_004b: ldloc.s CS$5$0002 | |
IL_004d: callvirt instance string class [mscorlib]System.Collections.Generic.IEnumerator`1<string>::get_Current() | |
IL_0052: pop | |
IL_0053: ldloc.s CS$5$0002 | |
IL_0055: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext() | |
IL_005a: brtrue.s IL_004b | |
} | |
IL_005c: leave.s IL_006a | |
} | |
finally | |
{ | |
IL_005e: ldloc.s CS$5$0002 | |
IL_0060: brfalse.s IL_0069 | |
IL_0062: ldloc.s CS$5$0002 | |
IL_0064: callvirt instance void [mscorlib]System.IDisposable::Dispose() | |
IL_0069: endfinally | |
} | |
IL_006a: ldloc.2 | |
IL_006b: callvirt instance class [mscorlib]System.Collections.Generic.IEnumerator`1<string> class [mscorlib]System.Collections.Generic.IEnumerable`1<string>::GetEnumerator() | |
IL_0070: stloc.3 | |
.loop | |
{ | |
IL_0071: ldloc.3 | |
IL_0072: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext() | |
IL_0077: brtrue.s IL_0071 | |
} | |
IL_0079: ret | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment