C#.NET — What does the declaration below represent? Choose the correct statements. Code: int[] intMyArr = {11, 3, 5, 9, 4}; Which are true? intMyArr is a reference to an object of System.Array. intMyArr is a reference to an object of a class that the compiler derives from System.Array. intMyArr is a reference to an array of integers. intMyArr is a reference to an object created on the stack. intMyArr is a reference to an array created on the stack.

Difficulty: Easy

Correct Answer: 1 and 3 only

Explanation:


Introduction / Context:
This question checks understanding of array types and memory model in C#. Arrays are reference types whose runtime types derive from System.Array. The variable itself is a reference; the array object lives on the managed heap, not the stack.


Given Data / Assumptions:

  • int[] intMyArr = {11, 3, 5, 9, 4};
  • Local variable context typical of console examples.


Concept / Approach:
An array instance such as System.Int32[] is a reference type whose base class is System.Array. Therefore statements describing it as (a) an object of System.Array (as a base type) and (c) a reference to an array of integers are acceptable. Claims about stack allocation for the array object are false: the array object is on the managed heap; only the local reference variable typically resides on the stack (implementation dependent, but conceptually distinct). The compiler does not literally “derive” a new class per declaration; array types are provided by the runtime and are already derived from System.Array.


Step-by-Step Solution:

(1) True — all arrays derive from System.Array. (2) False — no new class is derived by the compiler; the array type exists as System.Int32[]. (3) True — intMyArr is a reference to an integer array. (4) False — the object itself is not on the stack. (5) False — same reason; arrays are heap-allocated objects.


Verification / Alternative check:
Printing intMyArr.GetType().BaseType yields System.Array, confirming inheritance.


Why Other Options Are Wrong:
Any option including (2), (4), or (5) asserts incorrect derivation or storage location.


Common Pitfalls:
Equating the reference variable's storage with the array object's storage; assuming compiler creates new array classes per declaration.


Final Answer:
1 and 3 only

More Questions from Arrays

Discussion & Comments

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