C#.NET — Pick the correct fact about arrays: rank, length, default values, and sorting.

Difficulty: Easy

Correct Answer: The default value of numeric array elements is zero.

Explanation:


Introduction / Context:
This conceptual MCQ checks basic facts about C# arrays: allowed element types, the meaning of rank and length, default initialization of elements, and whether arrays are automatically sorted by the runtime.


Given Data / Assumptions:

  • We are considering CLR-managed arrays in C#.


Concept / Approach:
Arrays are reference types whose elements are initialized to default values (0 for numeric types, false for bool, null for reference types). Rank is the number of dimensions (e.g., 1 for int[], 2 for int[ , ]). Length is the total number of elements across all dimensions. No automatic sorting occurs upon creation or assignment.


Step-by-Step Solution:

Check each statement: A — False: arrays can hold any single element type, including reference types and user-defined structs. B — False: rank is dimension count, not total elements. C — False: length is total elements; rank is number of dimensions. D — True: numeric arrays default to 0 for all entries. E — False: elements are not automatically sorted.


Verification / Alternative check:
Create int[3] a = new int[3]; printing values shows 0 0 0; a.Rank returns 1; a.Length returns 3.


Why Other Options Are Wrong:
They contradict the CLR definitions of rank, length, and default initialization, or claim an unsupported guarantee (sorting).


Common Pitfalls:
Confusing rank with length, and assuming arrays of value types are uninitialized (they are zero-initialized by the runtime).


Final Answer:
The default value of numeric array elements is zero.

More Questions from Arrays

Discussion & Comments

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