Had to look this up, I've written precisely 0 lines of IL, but your question is interesting:
.maxstack is the
maximum evaluation stack depth/height, going through the IL, you only have a mamximum of 1 thing on the evaluation stack:
.locals init ([0] int32 first,
[1] int32 second,
[2] int32 third,
[3] int32 forth,
[4] int32 fifth)
Declares the local variables.
IL_0000: nop
No-operation?? - Does nothing, so why bother? Like I say, I'm not an expert in this stuff.
IL_0001: ldc.i4.s 10
Loads the constant 10 into the evaluation stack, stack size= 1.
IL_0003: stloc.0
Pops the value off the evaluation stack into locals[0]. evaluation stack size=0. Rinse & repeat for the other variables, but the max evaluation stack
size remains 1 because each of the 5 values is pushed into stack and popped into the variables individually.
I suppose you could hypothetically re-write like something this (probably won't compile) :
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
.maxstack 5
.locals init ([0] int32 first,
[1] int32 second,
[2] int32 third,
[3] int32 forth,
[4] int32 fifth)
IL_0000: nop
IL_0001: ldc.i4.s 10
IL_0003: ldc.i4.s 20
IL_0004: ldc.i4.s 30
IL_0006: ldc.i4.s 40
IL_0007: ldc.i4.s 50
IL_0009: stloc.4
IL_000a: stloc.3
IL_000c: stloc.2
IL_000d: stloc.1
IL_000f: stloc.0
IL_0011: ret
}
[Edit]
This is in response to the comments by yuthub, it must be read with the caveat that MSIL/CIL is well outside my comfort zone:
There is more than one stack in operation when running. When the const is pushed by the ldc, it is pushed onto the
evaluation stack (see
here[
^] for a good article). When the value is popped from the evaluation stack, in this case, being an int declare in a method, it is placed into a different stack, the stack is the one we'd normally discuss as "The stack" when discussing stack vs heap memory in c# for example. I've updated the earlier part of my question to help clarify.