In this lesson, you will learn how the .NET Runtime reads your compiled code by deconstructing the metadata and type signatures embedded within Intermediate Language (IL).
When you compile C# code, the compiler doesn't produce machine code directly. Instead, it generates Common Intermediate Language (CIL). This is a CPU-agnostic instruction set that acts as the "lingua franca" of the .NET ecosystem. To understand how the CLR interprets this, you must look at how it maps your high-level types to the underlying binary structure.
The Role of Metadata
Every assembly contains a Metadata Table. When the CLR loads your code, it doesn't just look at instructions; it looks at a "map" that defines every type, method, field, and property.
Consider this simple class:
public class User {
public int Id;
}
When compiled, the IL doesn't just say "create a class." It generates a TypeDef (Type Definition) table entry. If you were to inspect this via a tool like ildasm, you would see a signature that looks something like:
public auto ansi beforefieldinit User extends [System.Runtime]System.Object
The CLR uses this signature to allocate memory and define the object’s layout before a single line of your logic executes.
Deconstructing Signatures
The CLR treats type signatures as a series of tokens. When you call new User(), the IL uses the newobj instruction followed by a Token. This token points directly to the metadata table where the CLR finds the constructor signature, the size of the object in bytes, and the base class (System.Object).
By decoupling the high-level C# syntax from the IL metadata, the JIT (Just-In-Time) compiler can perform "on-the-fly" optimizations. It validates the type safety of your code at runtime by comparing these tokens against the definitions loaded in the app domain, ensuring that an int is never treated as a string before execution begins.
Key Takeaway: The CLR interprets your code by using metadata tokens as pointers to a structured map, allowing it to verify type safety and memory layout before executing the actual IL instruction stream.