Microsoft intermediate language in .NET | Understanding MSIL
It’s always good to be clear with the basics before you take the dive into .NET field. MSIL also many times referred to as CIL(Common Intermediate Language) or just IL(Intermediate Language).
How MSIL works
Before we go to understand MSIL I would like to explain how the traditional compilation process actually works. In Old languages like C and C++, the conversion of the source codes to the executable version just a one stage process.
The c compiler would compile the source code and convert it into the executable file which will be need for the execution of the source code.
As the community of coders increased it was found that coders had started making preference in the language that they would like to code in. Some liked to code in C++, others in Java and many other such languages.
There was a major problem faced by developers when more than two developers with different language preferences had to work on the same project. It really happens.
So there was a need of something like platform or language independent which does not have concern with the platform. It means write your code once in any language C# , F# , VB or any other and it can run on different environment.
The same thing is provided in .NET i.e. compiler translates the source code in MSIL :
“Microsoft Intermediate Language” . This code is not specific to any platform or processor, MSIL code is platform or CPU independent. It is like bytecode in JAVA. Though it is platform independent it is not executable.
To execute MSIL code, this code has been sent to CLR and converted into native code (CPU executable code) using Just In Time (JIT) compiler.
The execution is like :
Source Code => MSIL (or IL or CIL) code => Native Code
With MSIL , compiler also produces Metadata, both kept in PE : Portable Executable files. MSIL performs many task and contains instruction useful for loading, initializing, storing, control flow, exception handling, object creation & manipulation, type conversion and many other operations.