DEV Community

Cover image for DotNet Basics: What is the Common Intermediate Language?
JarrydLeePatel
JarrydLeePatel

Posted on

DotNet Basics: What is the Common Intermediate Language?

The Common Intermediate Language (CIL), sometimes referred to as Intermediate Language (IL), is the low-level programming language that all .NET-compatible languages—such as C#, VB.NET, and F#—are compiled into.

How Does CIL Work?
Compilation Time: When you write code in a .NET language like C#, the compiler does not directly generate machine code. Instead, it compiles the source code into CIL.

Runtime Execution:
At runtime, the Just-In-Time (JIT) compiler translates the CIL into binary (machine) code, which is then executed by the CPU.
All .NET languages compile to the same intermediate language, this enables cross-language interoperability—for example, a C# class can inherit from an F# class seamlessly.

Viewing CIL Code
To see the CIL code generated from your .NET project, you can use the IL Disassembler (ildasm.exe) tool, which is included with the .NET SDK.

Steps to View CIL Code:

  1. Locate the compiled DLL or EXE:
  2. After building your project, navigate to bin/Debug/netX.X/ (replace X.X with your .NET version).
  3. Open ILDASM:
  4. Run ildasm.exe from the Developer Command Prompt.
  5. Drag and drop your DLL or EXE into ILDASM.
  6. This will show you the CIL code that your source code was compiled into.

What is the Just-In-Time (JIT) Compiler?
The JIT Compiler is a feature of the Common Language Runtime (CLR) that translates CIL into machine code at runtime, just before the code is executed. This allows .NET applications to run efficiently on different hardware architectures while still maintaining performance.

Why is CIL Important?

  • Interoperability: Different .NET languages can work together since they compile to the same CIL.

  • Portability: CIL code is platform-independent until JIT compiles it to machine code.

  • Security & Optimization: The CLR can apply runtime optimizations based on the executing environment.

Final Thoughts:
Understanding CIL and how the JIT compiler works gives you deeper insights into .NET's inner workings. Whether you’re debugging, optimizing performance, or experimenting with cross-language compatibility, knowing how .NET compiles and executes code can make you a better developer.

Top comments (2)

Collapse
 
devh0us3 profile image
Alex P

Hello, or just for fun you may use sharplab, example:

sharplab.io/#v2:C4LglgNgNAJiDUAfAA...

Image description

Collapse
 
jarrydleepatel profile image
JarrydLeePatel

So true! Thanks @devh0us3