Difficulty: Easy
Correct Answer: arr.Count
Explanation:
Introduction / Context:
ArrayList is a resizable array in System.Collections. Knowing the difference between capacity and count is key for correct memory and performance management.
Given Data / Assumptions:
Concept / Approach:
ArrayList exposes two size-related members: Count and Capacity. Count returns how many elements are currently stored. Capacity is the size of the internal array (allocation) and may be greater than Count. Other listed members either do not exist or are not used for this purpose.
Step-by-Step Solution:
Verification / Alternative check:
Add items and inspect Count vs. Capacity in a debugger; Count increases by one per Add, Capacity grows in steps.
Why Other Options Are Wrong:
They either refer to non-existent members or to Capacity, which is distinct from count.
Common Pitfalls:
Using Capacity to loop can lead to null entries or index errors. Always iterate up to Count.
Final Answer:
arr.Count
Discussion & Comments