Managed Code in .NET: which statement most accurately defines it?

Difficulty: Easy

Correct Answer: Managed code is the code that is written to target the services of the CLR.

Explanation:


Introduction / Context:
“Managed code” is a core term in the .NET world. It distinguishes code that executes under the control of the Common Language Runtime (CLR) from “unmanaged” native code that runs directly on the OS without CLR services. Knowing the accurate definition prevents confusion about platforms, JIT compilation, and memory management details.


Given Data / Assumptions:

  • The CLR provides services such as type safety, security, metadata, exception handling, and garbage collection.
  • JIT compilation and GC are common in managed execution but are not the defining properties by themselves.
  • Managed vs. unmanaged is not tied to a specific OS like Windows or Linux.


Concept / Approach:

The most precise definition is: managed code is code written to target the CLR's managed execution environment and its services. While such code is typically JIT-compiled and garbage-collected, those are consequences of being managed, not independent definitions. Managed status says nothing about a particular operating system; with modern .NET, managed code can run cross-platform.


Step-by-Step Solution:

Identify the essential criterion: code that targets CLR services and metadata. Differentiate incidental traits (JIT, GC) from the core definition. Eliminate OS-specific statements; management is runtime-bound, not OS-bound. Select the CLR-centric definition (option D).


Verification / Alternative check:

Inspect IL and metadata in a managed assembly (e.g., with ILDasm). It clearly targets the CLR; the runtime provides JIT and GC, confirming managed execution. Native C/C++ binaries lack CLR metadata and thus are unmanaged.


Why Other Options Are Wrong:

JIT-compiled / Garbage Collected: traits of managed execution but not definitional.

Runs on top of Windows / Linux: platform statements; managedness is about CLR, not OS.


Common Pitfalls:

  • Assuming all JITed code is managed—JIT is a mechanism, not a definition.
  • Equating garbage collection with being managed—many managed scenarios involve GC, but GC alone does not imply CLR-managed.


Final Answer:

Managed code is the code that is written to target the services of the CLR.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion