BCA / B.Tech 10 min read

Intermediate Language in .NET

Intermediate Language (IL) in .NET in Hindi | Intermediate Language in Hindi:


What is Intermediate Language (IL)?

  • In the .NET Framework, Intermediate Language (IL) is also known as Microsoft Intermediate Language (MSIL) or just Common Intermediate Language (CIL).
  •  It is a low-level programming language that is compiled for all .NET programs.
  • When we write code in any of the .NET languages (like C#, VB.NET, F#), that code is not directly understandable by the machine.
  • That code is first compiled into Intermediate Language (IL).
Process of Intermediate Language in Hindi | Process of Intermediate Language:

  • .NET's Just-In-Time (JIT) Compiler converts this IL into machine code at runtime, which can be understood by the CPU.
Steps of the IL process:

Source Code:

  • The programmer writes code in any of the .NET languages (like C#, VB.NET).
  • Compilation: This code is compiled into Intermediate Language (IL) by the .NET Compiler and is saved as a .dll or .exe file.
  • Execution (runtime): When this program is run, the .NET Common Language Runtime (CLR) converts the IL into machine code.
Advantages of Intermediate Language in Hindi | Advantages of Intermediate Language:

  • Language Interoperability: Code written in different languages under .NET (like C#, VB.NET) is compiled into the same IL. This means that all languages can work together.
  • Platform Independence: IL code is not platform-dependent. It can work on any platform where the .NET Framework or .NET Core is available.
  • Performance Optimization: The JIT Compiler optimizes the code at runtime, which results in better performance.
  • Security: IL code is monitored by the CLR, which makes the code more secure.
Main features of Intermediate Language:

  • Stack-Based Architecture: IL works on a stack-based architecture, where data is loaded into the stack and processed.
  • Object-Oriented: IL has all the features of object-oriented programming (OOP).
  • Stored in Assembly: IL code is stored as a .exe or .dll file. This is called an Assembly.
  • Flexibility: IL code can be easily converted to other languages.
Example of Intermediate Language:

C# code:

using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Hello, World!");
    }
}
IL code: When it is compiled into IL, it looks something like this:

.method public hidebysig static void Main() cil managed
{
    .entrypoint
    IL_0000: ldstr "Hello, World!"
    IL_0005: call void [mscorlib]System.Console::WriteLine(string)
    IL_000A: ret
}
  • ldstr means "load string".
  • call means to call a method.
  • ret means "return".
Functioning of Intermediate Language:

1. Common Language Infrastructure (CLI): The CLI is a standard of .NET, in which IL is used. It makes .NET multi-language and platform-independent.

2. Common Language Runtime (CLR): The CLR does the work of converting IL to machine code at runtime.

3. JIT Compiler: The JIT Compiler converts IL to machine code. This process is fast and optimized.

Why is Intermediate Language important?

  • A common basis for different languages: The .NET Framework supports many languages. IL acts as a common language for all languages.
  • Optimization at runtime: The JIT Compiler optimizes IL while converting it to machine code, which improves the performance of the application.
  • Portability: IL code can be run on any platform where the CLR is available.
Intermediate Language and the future of .NET

  • The use of IL is not only on the .NET Framework but also on platforms like .NET Core and now .NET 6/7. This makes .NET more flexible and powerful.
  • It is being used for gaming, web applications, mobile applications, and cloud-based solutions. IL is a fundamental part of all modern technologies that come with .NET.
  • Intermediate Language is one of the fundamental parts of .NET, which provides the facility for different languages and platforms to work together.