#658 – What Boxing and Unboxing Look Like in IL

Recall that your C# source code is compiled to a platform-neutral intermediate language called Common Intermediate Language.  You can view the IL for your application, after building the code, using the IL Disassembler tool.

If you look at the IL generated for code that boxes or unboxes a value, you’ll see unique CIL instructions for boxing (box) and unboxing (unbox).

Assume that you box an int value and then later unbox it.

int x = 12;

object o = x;    // Box

int y = (int)o;  // Unbox

If you build this code and look at the IL, you’ll see the box and unbox instructions.