Skip to content

Instantly share code, notes, and snippets.

@werat
Created August 24, 2012 15:34
Show Gist options
  • Save werat/3452051 to your computer and use it in GitHub Desktop.
Save werat/3452051 to your computer and use it in GitHub Desktop.
C# and IL code for some example
internal class Thing
{
public string A { get; set; }
}
// C# Code
private static void M1(Thing thing)
{
thing.A = thing.A + 10;
}
// IL Code
.method private hidebysig static
void M1 (
class Test.Thing thing
) cil managed
{
// Method begins at RVA 0x2072
// Code size 27 (0x1b)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldarg.0
IL_0003: callvirt instance string Test.Thing::get_A()
IL_0008: ldc.i4.s 10
IL_000a: box [mscorlib]System.Int32
IL_000f: call string [mscorlib]System.String::Concat(object, object)
IL_0014: callvirt instance void Test.Thing::set_A(string)
IL_0019: nop
IL_001a: ret
} // end of method Program::M1
// C# Code
private static void M2(Thing thing)
{
thing.A += 10;
}
// IL Code
.method private hidebysig static
void M2 (
class Test.Thing thing
) cil managed
{
// Method begins at RVA 0x208e
// Code size 27 (0x1b)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.0
IL_0002: dup
IL_0003: callvirt instance string Test.Thing::get_A()
IL_0008: ldc.i4.s 10
IL_000a: box [mscorlib]System.Int32
IL_000f: call string [mscorlib]System.String::Concat(object, object)
IL_0014: callvirt instance void Test.Thing::set_A(string)
IL_0019: nop
IL_001a: ret
} // end of method Program::M2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment