C#.NET — Identify the correct statement about structs, value types, and the type system.

Difficulty: Easy

Correct Answer: All value types in C# inherently derive from ValueType, which inherits from Object.

Explanation:


Introduction / Context:
This question checks your understanding of the Common Language Runtime (CLR) type hierarchy and where structs (value types) fit in the C#.NET ecosystem. Knowing the inheritance chain is essential for understanding boxing, method availability, and how value types are treated at runtime.


Given Data / Assumptions:

  • We compare statements about constructors, destructors (finalizers), and the relationship among Object, ValueType, and user-defined structs.
  • Assume standard C# behavior as understood in foundational .NET topics.


Concept / Approach:
In C#, every value type (such as int, bool, and any user-defined struct) ultimately derives from System.ValueType, and System.ValueType itself derives from System.Object. This ensures all value types inherit Object members (e.g., ToString, GetHashCode) and can be boxed to Object. The distractors mix in claims about constructors and destructors and equating classes with structs, which are not accurate in the general case.


Step-by-Step Solution:

Confirm the .NET inheritance chain for value types: StructName → System.ValueType → System.Object. Evaluate option A: historically, parameterless struct constructors are supplied by the runtime; user-defined parameterless constructors were disallowed in earlier C#, and are not the focus here. The statement as written is too absolute and context-sensitive. Evaluate option C: structs cannot have finalizers at all; wording “default destructor” is imprecise and misleading. Evaluate option D: classes (reference types) and structs (value types) differ in semantics such as allocation, identity, assignment, and inheritance. Therefore, option B is the clearly correct statement that reflects the CLR type hierarchy.


Verification / Alternative check:
Reflecting on any struct type via GetType().BaseType shows System.ValueType; ValueType.BaseType is System.Object. Boxing a struct references it as System.Object.


Why Other Options Are Wrong:

  • A: Over-broad and tied to language-version nuances; the key concept being tested is the type hierarchy.
  • C: Talks about “default destructor”; structs do not have destructors.
  • D: Structs and classes have fundamentally different semantics.
  • E: Incorrect because a correct statement exists (B).


Common Pitfalls:
Confusing the CLR hierarchy, assuming structs behave like classes, or misinterpreting destructor/constructor rules for value types.


Final Answer:
All value types in C# inherently derive from ValueType, which inherits from Object.

More Questions from Structures

Discussion & Comments

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