Under the Hood

How does the CLR know what type contains the entry point and how it’s called? Even though we didn’t explicitly state this, the containing type’s name doesn’t matter. In line with Visual Studio’s choice, we used Program, but that’s not mandatory. So, the idea of the CLR having hard-coded knowledge about looking for a method called Main on a type called Program falls apart.

It turns out the CLR doesn’t care about the name of the method or its containing type at all; instead, the answer lies in metadata used to keep track of the entry-point method within the defining assembly. You can see this using ildasm.exe when looking at the code for the entry-point method. From a Developer Command Prompt, run ildasm on the executable file and ...

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.