Free mag vol1 | Page 716

CHAPTER 18  UNDERSTANDING CIL AND THE ROLE OF DYNAMIC ASSEMBLIES } IL_000b: IL_000c: IL_0011: IL_0012: nop call string [mscorlib]System.Console::ReadLine() pop ret The implementation of the default constructor in terms of CIL code makes use of yet another “loadcentric” instruction (ldarg.0). In this case, the value loaded onto the stack is not a custom variable specified by you, but the current object reference (more details on this later). Also note that the default constructor explicitly makes a call to the base class constructor, as follows (which, in this case, is your good friend System.Object): .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { .maxstack 8 IL_0000: ldarg.0 IL_0001: call instance void [mscorlib]System.Object::.ctor() IL_0006: ret } The Role of CIL Code Labels One thing you certainly have noticed is that each line of implementation code is prefixed with a token of the form IL_XXX: (e.g., IL_0000:, IL_0001:, and so on). These tokens are called code labels and may be named in any manner you choose (provided they are not duplicated within the same member scope). When you dump an assembly to file using ildasm.exe, it will automatically generate code labels that follow an IL_XXX: naming convention. However, you may change them to reflect a more descriptive marker. For example: .method private hidebysig static void Main(string[] args) cil managed { .entrypoint .maxstack 8 Nothing_1: nop Load_String: ldstr "Hello CIL code!" PrintToConsole: call void [mscorlib]System.Console::WriteLine(string) Nothing_2: nop WaitFor_KeyPress: call string [mscorlib]System.Console::ReadLine() RemoveValueFromStack: pop Leave_Function: ret } The truth of the matter is that most code labels are completely optional. The only time code labels are truly mandatory is when you are authoring CIL code that makes use of various branching or looping constructs, as you can specify where to direct the flow of logic via these code labels. For the current example, you can remove these autogenerated labels altogether with no ill effect, like so: .method private hidebysig static void Main(string[] args) cil managed { .entrypoint .maxstack 8 nop 659