Using 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 the lines 11-14 do? I call a function and get a result (line 7). I cast the result to the right returntype (line c) - why not return right now?
Somehow, the casted result is stored as a local variable - then there is an uncoditional jump 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 ... ?