What are these opcodes for?

Using a reflector, I get the following output:

.method private hidebysig static class myModelTestarea.Foo Method() cil managed
{
  .maxstack 1
  .locals init ([0] class myModelTestarea.Foo CS$1$0000)
  L_0000: nop 
  L_0001: ldc.i4.0 
  L_0002: newarr object
  L_0007: call object myModelTestarea.Program::Resolve(object[])
  L_000c: castclass myModelTestarea.Foo
  L_0011: stloc.0 
  L_0012: br.s L_0014
  L_0014: ldloc.0 
  L_0015: ret 
}

for

private static Foo Method()
{
  return (Foo)Resolve();
}

private static object Resolve( params object[] args )
{
  return new Foo();
}

What do lines 11-14 do? I call the function and get the result (line 7). I passed the result to the correct return (line c) - why not return right now?

Somehow, the cast result is saved as a local variable - then there is the next transition to the next line, where the local variable is loaded again. Why?

In my opinion, line 11-14 and the local variable can be omitted ...?

+5
source share
2 answers

DEBUG, IL, . RELEASE, , ..

.method private hidebysig static class program/Foo Method() cil managed
{
    .maxstack 8
    L_0000: ldc.i4.0 
    L_0001: newarr object
    L_0006: call object program::Resolve(object[])
    L_000b: castclass program/Foo
    L_0010: ret 
}
+13

? , .

- . , JIT, . , IL JIT, .

+4

All Articles