The Common Language Runtime, or CLR, is the execution engine at the heart of .NET. Microsoft describes it as “a runtime environment called the common language runtime that runs the code and provides services that make the development process easier.” It is, in effect, .NET’s virtual machine, playing the same role for .NET languages that the Java Virtual Machine plays for Java.
Code written for .NET is not compiled straight to machine instructions. Compilers emit Intermediate Language (IL), also called Common Intermediate Language. Microsoft explains that when you want to run IL, “this is where the CLR takes over and starts the process of Just-In-Time compiling, or JIT-ing your code from IL to machine code that can actually be run on a CPU.” Because the runtime sits between the program and the hardware, “the CLR knows exactly what your code is doing and can effectively manage it.”
Beyond compilation, the CLR provides the services that define managed code. Microsoft notes that “the runtime automatically handles object layout and manages references to objects, releasing them when they’re no longer being used,” and that “garbage collection eliminates memory leaks and some other common programming errors.” It also enforces type safety, security boundaries, structured exception handling, and versioning, using metadata that every compiled .NET module carries with it.
A distinctive feature is cross-language integration. Because compilers all target a common type system defined by the runtime, “objects written in different languages can communicate with each other,” and a class defined in one language can be derived from or called by another. This is possible because the type system, metadata format, and virtual execution system are all fixed by a public standard, the ECMA Common Language Infrastructure specification.