After running ILDASM on two assemblies generated from identical C# code (but potentially different compiler versions), I get the following output, from each respective dll.
.locals init (class MyClass/'<>c__DisplayClass3' V_0)
and
.locals init ([0] class MyClass/'<>c__DisplayClass3' 'CS$<>8__locals4')
What is the difference between these two statements, specifically, what is the significance of the '[0]' symbol?
The two statements are functionally identical. The difference is caused by ILDASM using data from a .pdb in the second case. When debugging information is available, ILDASM includes the variable name and index; otherwise it gives them generic names and omits the index.
I can only speculate that the index is included to help you associate any
ldloc.xinstructions with their variable names.As an aside, explicitly supplying the variable index could be useful when editing MSIL by hand, since it may prevent you from making a mistake when adding or removing locals:
If you later removed
xwithout reviewing your method and fixing up your indexes: