Skip to content

Instantly share code, notes, and snippets.

@acple acple/Program.cs

Created Oct 20, 2017
Embed
What would you like to do?
lambda capture
using System;
namespace ConsoleApp
{
class Program
{
static void Main()
{
var a = 1;
{
var b = 2;
{
var c = 3;
var func = (Func<int>)(() => a + b + c);
func.Invoke();
}
}
}
}
}
.class private auto ansi beforefieldinit ConsoleApp.Program
extends [System.Runtime]System.Object
{
// Nested Types
.class nested private auto ansi sealed beforefieldinit '<>c__DisplayClass0_0'
extends [System.Runtime]System.Object
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
01 00 00 00
)
// Fields
.field public int32 a
// Methods
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [System.Runtime]System.Object::.ctor()
IL_0006: ret
} // end of method '<>c__DisplayClass0_0'::.ctor
} // end of class <>c__DisplayClass0_0
.class nested private auto ansi sealed beforefieldinit '<>c__DisplayClass0_1'
extends [System.Runtime]System.Object
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
01 00 00 00
)
// Fields
.field public int32 b
.field public class ConsoleApp.Program/'<>c__DisplayClass0_0' 'CS$<>8__locals1'
// Methods
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [System.Runtime]System.Object::.ctor()
IL_0006: ret
} // end of method '<>c__DisplayClass0_1'::.ctor
} // end of class <>c__DisplayClass0_1
.class nested private auto ansi sealed beforefieldinit '<>c__DisplayClass0_2'
extends [System.Runtime]System.Object
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
01 00 00 00
)
// Fields
.field public int32 c
.field public class ConsoleApp.Program/'<>c__DisplayClass0_1' 'CS$<>8__locals2'
// Methods
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [System.Runtime]System.Object::.ctor()
IL_0006: ret
} // end of method '<>c__DisplayClass0_2'::.ctor
.method assembly hidebysig
instance int32 '<Main>b__0' () cil managed
{
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld class ConsoleApp.Program/'<>c__DisplayClass0_1' ConsoleApp.Program/'<>c__DisplayClass0_2'::'CS$<>8__locals2'
IL_0006: ldfld class ConsoleApp.Program/'<>c__DisplayClass0_0' ConsoleApp.Program/'<>c__DisplayClass0_1'::'CS$<>8__locals1'
IL_000B: ldfld int32 ConsoleApp.Program/'<>c__DisplayClass0_0'::a
IL_0010: ldarg.0
IL_0011: ldfld class ConsoleApp.Program/'<>c__DisplayClass0_1' ConsoleApp.Program/'<>c__DisplayClass0_2'::'CS$<>8__locals2'
IL_0016: ldfld int32 ConsoleApp.Program/'<>c__DisplayClass0_1'::b
IL_001B: add
IL_001C: ldarg.0
IL_001D: ldfld int32 ConsoleApp.Program/'<>c__DisplayClass0_2'::c
IL_0022: add
IL_0023: ret
} // end of method '<>c__DisplayClass0_2'::'<Main>b__0'
} // end of class <>c__DisplayClass0_2
// Methods
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [System.Runtime]System.Object::.ctor()
IL_0006: ret
} // end of method Program::.ctor
.method private hidebysig static
void Main () cil managed
{
.maxstack 3
.entrypoint
.locals init (
[0] class ConsoleApp.Program/'<>c__DisplayClass0_0',
[1] class ConsoleApp.Program/'<>c__DisplayClass0_1'
)
IL_0000: newobj instance void ConsoleApp.Program/'<>c__DisplayClass0_0'::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: ldc.i4.1
IL_0008: stfld int32 ConsoleApp.Program/'<>c__DisplayClass0_0'::a
IL_000D: newobj instance void ConsoleApp.Program/'<>c__DisplayClass0_1'::.ctor()
IL_0012: stloc.1
IL_0013: ldloc.1
IL_0014: ldloc.0
IL_0015: stfld class ConsoleApp.Program/'<>c__DisplayClass0_0' ConsoleApp.Program/'<>c__DisplayClass0_1'::'CS$<>8__locals1'
IL_001A: ldloc.1
IL_001B: ldc.i4.2
IL_001C: stfld int32 ConsoleApp.Program/'<>c__DisplayClass0_1'::b
IL_0021: newobj instance void ConsoleApp.Program/'<>c__DisplayClass0_2'::.ctor()
IL_0026: dup
IL_0027: ldloc.1
IL_0028: stfld class ConsoleApp.Program/'<>c__DisplayClass0_1' ConsoleApp.Program/'<>c__DisplayClass0_2'::'CS$<>8__locals2'
IL_002D: dup
IL_002E: ldc.i4.3
IL_002F: stfld int32 ConsoleApp.Program/'<>c__DisplayClass0_2'::c
IL_0034: ldftn instance int32 ConsoleApp.Program/'<>c__DisplayClass0_2'::'<Main>b__0'()
IL_003A: newobj instance void class [System.Runtime]System.Func`1<int32>::.ctor(object, native int)
IL_003F: callvirt instance !0 class [System.Runtime]System.Func`1<int32>::Invoke()
IL_0044: pop
IL_0045: ret
} // end of method Program::Main
} // end of class ConsoleApp.Program
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.