CLR (Common Language Runtime) — Explained with Examples
CLR (Common Language Runtime) is the virtual machine component of Microsoft’s .NET framework. It executes programs written in any .NET language (C#, F#, VB.NET) by compiling their Common Intermediate Language (CIL) bytecode into native machine code, typically via JIT compilation.
The CLR provides services analogous to the JVM: garbage collection (generational), exception handling, type safety verification, security, and threading. The Common Language Specification (CLS) and Common Type System (CTS) ensure language interoperability — a C# class can inherit from a VB.NET class, and an F# function can be called from C#. Modern .NET (Core 5+) uses RyuJIT as the JIT compiler, with support for AOT via ReadyToRun and Native AOT.
Real-world analogy. The CLR is like a United Nations translation hub. Delegates speak different languages (C#, F#, VB.NET). Their speeches are transcribed into a universal notation (CIL). The hub then translates the notation into each delegate’s language (native code) and provides services like sound systems (GC) and security screening (verification).
Example (C# to CIL conceptual):
// C#
int Add(int a, int b) => a + b;
// CIL (simplified)
// ldarg.0
// ldarg.1
// add
// retRelated terms: JVM, Garbage Collection, JIT Compilation, AOT Compilation, Compiled vs Interpreted
Related tutorial: CLR and .NET Runtime
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro