Difficulty: Easy
Correct Answer: 3, 4
Explanation:
Introduction / Context:
In C#.NET, arrays expose members that help you discover their shape. Two commonly discussed members are Length (the total element count) and GetUpperBound(dimension) (the highest valid index along a dimension). This question asks which options are valid approaches to determine how many elements the given one-dimensional array actually contains.
Given Data / Assumptions:
Concept / Approach:
For any array a, a.Length returns the total number of elements. For a one-dimensional array, a.GetUpperBound(0) returns the last valid index (zero-based). Therefore, a.GetUpperBound(0) + 1 equals the count. Names like GetMax, Highest, or GetMaxElements are not valid .NET array APIs.
Step-by-Step Solution:
Verification / Alternative check:
Printing intMyArr.Length yields 5. Printing intMyArr.GetUpperBound(0) yields 4, confirming that adding one gives the count.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing final index (upper bound) with element count; remember to add one when using GetUpperBound for 1-D arrays.
Final Answer:
3, 4
Discussion & Comments