Skip to content

Instantly share code, notes, and snippets.

@bojanrajkovic
Created October 26, 2010 20:05
Show Gist options
  • Save bojanrajkovic/647668 to your computer and use it in GitHub Desktop.
Save bojanrajkovic/647668 to your computer and use it in GitHub Desktop.
Emitted IL
// method line 2
.method public static hidebysig
default void Main (string[] args) cil managed
{
// Method begins at RVA 0x20f4
.entrypoint
// Code size 135 (0x87)
.maxstack 10
.locals init (
string V_0,
string V_1,
class [mscorlib]System.Collections.Generic.Dictionary`2<string, int32> V_2,
int32 V_3)
IL_0000: ldstr "Hello"
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: stloc.1
IL_0008: ldloc.1
IL_0009: brfalse IL_0077
IL_000e: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> Test::'<>f__switch$map0'
IL_0013: brtrue IL_003d
IL_0018: ldc.i4.2
IL_0019: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string, int32>::'.ctor'(int32)
IL_001e: stloc.2
IL_001f: ldloc.2
IL_0020: ldstr "Hello"
IL_0025: ldc.i4.0
IL_0026: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string, int32>::Add(!0, !1)
IL_002b: ldloc.2
IL_002c: ldstr "World"
IL_0031: ldc.i4.1
IL_0032: callvirt instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string, int32>::Add(!0, !1)
IL_0037: ldloc.2
IL_0038: stsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> Test::'<>f__switch$map0'
IL_003d: ldsfld class [mscorlib]System.Collections.Generic.Dictionary`2<string,int32> Test::'<>f__switch$map0'
IL_0042: ldloc.1
IL_0043: ldloca.s 3
IL_0045: callvirt instance bool class [mscorlib]System.Collections.Generic.Dictionary`2<string, int32>::TryGetValue(!0, [out] !1&)
IL_004a: brfalse IL_0077
IL_004f: ldloc.3
IL_0050: brfalse IL_0061
IL_0055: ldloc.3
IL_0056: ldc.i4.1
IL_0057: beq IL_006c
IL_005c: br IL_0077
IL_0061: ldc.i4.1
IL_0062: call void class [mscorlib]System.Console::WriteLine(bool)
IL_0067: br IL_0086
IL_006c: ldc.i4.0
IL_006d: call void class [mscorlib]System.Console::WriteLine(bool)
IL_0072: br IL_0086
IL_0077: ldstr "default"
IL_007c: call void class [mscorlib]System.Console::WriteLine(string)
IL_0081: br IL_0086
IL_0086: ret
} // end of method Test::Main
using System;
class Test {
public static void Main (string[] args) {
string h = "Hello";
switch (h) {
case "Hello":
Console.WriteLine (true);
break;
case "World":
Console.WriteLine (false);
break;
default:
Console.WriteLine ("default");
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment