Search code examples
c#cil

Why do we need MSIL in .net Framework


I wanna know when we compile .net source code it gets first converted to MSIL and then into binary executable code. I know MSIL is machine and language independent code.

But why it is converted to MSIL first before gets executed by CPU. What is the need of MSIL actually we have in .net framework ?


Solution

  • Of the top of my head:

    • It saves a lot of time, as MSIL is already optimized, let´s call it precompiled
    • MSIL is language independent, it doesn´t matter anymore if the code was written in C#, VB or F# or ..., meaning the "excecuting runtime" doesn´t need the correct compiler for every possible language
    • MSIL is platform independent
    • Google it