Explain the difference between “managed” and “unmanaged” code?

Technology CommunityCategory: .NET CoreExplain the difference between “managed” and “unmanaged” code?
VietMX Staff asked 3 years ago
  • Managed code is not compiled to machine code but to an intermediate language which is interpreted and executed by some service on a machine and is therefore operating within a (hopefully!) secure framework which handles dangerous things like memory and threads for you. It runs on the CLR (Common Language Runtime), which, among other things, offers services like garbage collection, run-time type checking, and reference checking. So, think of it as, “My code is managed by the CLR.”
  • Unmanaged code is compiled to machine code and therefore executed by the OS directly. It therefore has the ability to do damaging/powerful things Managed code does not. This is how everything used to work, so typically it’s associated with old stuff like .dlls