Managed code - Any piece of code that can be directly executed by the common language runtime (CLR) in a .Net environment is known as managed code. When a .Net program is compiled it is not directly converted to machine code, it is converted MSIL (Microsoft intermediate language) and CLR uses this MSIL to execute the program which is known as managed code. A managed code contains all the necessary metadata to CLR to enable services like code access security, memory management etc.
Unmanaged code – Programs or DLL’s written in other languages (like C, C++) are directly executed by the CPU directly. These are known as unmanaged code because the CLR doesn’t have any control over the execution of such codes.