C# & CLR Internals (50 Qs)•Part 1: Core Language, CLR & Memory Architecture (1 - 10)
What is the Common Language Runtime (CLR) and the Common Intermediate Language (CIL)?
senior LevelCode ExampleSystem Design
In Simple Words:
- CIL (Common Intermediate Language): The platform-agnostic bytecode generated when C# code is compiled by the Roslyn compiler.
- CLR (Common Language Runtime): The execution engine of .NET that provides memory management, garbage collection, thread pool management, type safety verification, exception handling, and JIT (Just-In-Time) compilation of CIL bytecode into native CPU instructions at runtime.
csharp
// Execution Pipeline:
// 1. C# Source Code (.cs)
// 2. Roslyn Compiler (csc) -> Compiles to Assembly (.dll) containing CIL + Metadata
// 3. CLR Loader -> Loads assembly, verifies type safety
// 4. RyuJIT Compiler -> Compiles hot CIL methods into native x86/x64/ARM64 machine instructions
public class Program
{
public static void Main()
{
Console.WriteLine($"Running on .NET Runtime: {Environment.Version}");
}
}