Intermediate Language (IL), also known as Common Intermediate Language (CIL), is a low-level programming language developed by Microsoft. It's a core part of Common Language Runtime (CLR), serving as an intermediary between the high-level code written by developers and the machine code executed by the processor.
Let's break down the key stages of .NET application compilation.
The use of Intermediate Language (IL) has several key advantages:
Let's take a look at the IL code of the simplest C# program:
class Program
{
public static void Main()
{
Console.WriteLine("Hello World!");
}
}
The exact output looks like this, but may vary slightly depending on the .NET version:
.class private auto ansi beforefieldinit Program
extends [System.Runtime]System.Object
{
.method public hidebysig static void Main() cil managed
{
.entrypoint
// Code size 13 (0xd)
.maxstack 8
IL_0000: nop
IL_0001: ldstr "Hello World!"
IL_0006: call void [System.Console]System.Console::WriteLine(string)
IL_000b: nop
IL_000c: ret
} // end of method Program::Main
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [System.Runtime]System.Object::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method Program::.ctor
} // end of class Program
IL code is also useful for understanding subtle language behaviors that aren't always obvious at the source level.
You can learn more about IL code in real cases in the following articles:
0