Is MSIL same as Managed Code in .NET?

.net, c#, compilation, il

Solution

You're confusing different things. Managed code is code that's written in a managed language (C#, VB.NET, F# and many others) that's compiled into CIL (Common Intermediate Language, formerly Microsoft Intermediate Language or MSIL) and run in the managed environment of CLR.

Unmanaged code, on the other hand is compiled directly into native code (also called assembly), it does not run on CLR.

When you build your C# code, it's compiled into CIL. This is why you can use tools like ildasm or Reflector to inspect the compiled code. What exactly happens when you execute the CIL code depends on circumstances. It could be

- compiled into native code “just in time” using the JIT compiler (the most common option).

- executed using a pre-compiled native code (you can use NGEN to get that).

- directly interpreted; I think some version of .Net for Windows CE, or similar does that.

Problem

I am confused with MSIL and Managed Code are they same or different? I mean to say, what happens when we built our C# code? Which one is right `C# Code → C# compiler → Managed Code → MSIL` or `C# Code → C# compiler → MSIL` Please provide authentic reference or link in support of your answer.

Original source