Difficulty: Easy
Correct Answer: True
Explanation:
Introduction / Context:
This True/False item tests whether you know that C# structs are value types by definition. This determines how they are allocated, passed, assigned, and how they interact with the managed heap and boxing/unboxing.
Given Data / Assumptions:
Concept / Approach:
Value types hold their data directly and are copied on assignment by value. Reference types hold references to objects on the heap. Regardless of where a variable is stored (e.g., a local on the stack or a field within a heap object), a struct remains a value type; only boxing wraps it into an object reference temporarily for polymorphic use as System.Object or interfaces.
Step-by-Step Solution:
Verification / Alternative check:
Use typeof(MyStruct).IsValueType to verify that any struct is a value type at runtime. Built-in types (System.Int32, System.Boolean) also return true.
Why Other Options Are Wrong:
Common Pitfalls:
Equating “stack vs heap” with “value vs reference.” Value/reference is a type system concept; stack/heap is an implementation detail of storage.
Final Answer:
True
Discussion & Comments