Look at the following piece the age old Hello World program in C#.
The above piece of code can be explained as having
- Defined a type called Program having a single public static method called Main
- Main refers to a type called System.Console which is written by Microsoft and the IL code that implements it is in a file called MsCorLib.dll
- To compile the program you could have executed the following statement:
- csc.exe /out:Program.exe /t[arget]:exe /r[eference]:MSCorLib.dll Program.cs
- But, the following statement also works:
- csc.exe Program.cs
- Reason being the fact that the compiler has some defaults and reference to MsCorLib.dll is one such default. Please note that MsCorLib.dll is the most critical of all .Net BCLs. It contains all the core types like String, Int32 etc, exe is another default.
- However, if you want to beak it try the following:
- csc.exe /nostdlib Program.cs
- /nostdlib asks the compiler to ignore MsCorLib.dll. If this switch is breaking a simple statement then why is it useful, you might ask.
- The reason is simple when the compiler compiles MsCorLib.dll is doesn’t need a reference to MsCorLib.dll does it? It uses the /nostdlib then.
As a result of the above command, a simple executable file called Program.exe is now created. Lets dive a little deeper into it.
- It’s a PE (Portable Executable) having the following:
- PE header(32/32+)
- CLR header
- To examine the Metadata within a managed PE file use ILDasm.exe
- It's also an Assembly.
See you soon!