C#.NET types and the Common Type System (CTS) — which statements are correct? 1) Every data type is either a value type or a reference type. 2) Value types are always created on the heap. 3) Reference types are always created on the stack. 4) Mapping of each value type to a CTS type facilitates interoperability. 5) Every reference type maps to a CTS type.

Difficulty: Easy

Correct Answer: 1, 4, 5

Explanation:


Introduction / Context:
The Common Type System (CTS) unifies types across .NET languages. Understanding how value and reference types map to CTS concepts helps when reasoning about memory allocation and inter-language compatibility.



Given Data / Assumptions:

  • We consider general rules for allocation and type mapping in .NET.
  • We ignore unsafe/pointer types here.


Concept / Approach:
(1) True: .NET classifies types broadly as value or reference. (2) False: value types are typically allocated inline (e.g., on the stack or within an object) and only exist on the heap when boxed. (3) False: reference type objects are allocated on the managed heap; variables that hold the references may live on the stack. (4) True: CTS mappings (e.g., System.Int32) enable cross-language interoperability. (5) True: all reference types map to CTS types as well (e.g., System.String, System.Object).



Step-by-Step Solution:

Confirm 1, 4, 5 as correct.Eliminate 2 and 3 based on allocation behavior.Select the answer grouping that contains 1, 4, 5.


Verification / Alternative check:
Examine IL or runtime behavior: boxing a value type creates a heap object; normal value-type locals exist without heap allocation.



Why Other Options Are Wrong:
They include false statements about allocation locations.



Common Pitfalls:
Assuming “stack vs. heap” is tied to type alone; in reality, context (boxing, field location) matters.



Final Answer:
1, 4, 5

More Questions from Datatypes

Discussion & Comments

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