Bird
0
0

Why does the Capacity property of a List<T> sometimes differ from Count?

hard🧠 Conceptual Q10 of 15
C Sharp (C#) - Collections
Why does the Capacity property of a List<T> sometimes differ from Count?
ACapacity is always equal to Count
BCapacity is the total allocated space; Count is actual elements stored
CCount includes null elements; Capacity does not
DCapacity decreases automatically when items are removed
Step-by-Step Solution
Solution:
  1. Step 1: Define Capacity and Count

    Capacity is how many elements the list can hold before resizing; Count is how many elements are currently in the list.
  2. Step 2: Understand difference behavior

    Capacity can be larger than Count to optimize performance; it does not shrink automatically on removals.
  3. Final Answer:

    Capacity is the total allocated space; Count is actual elements stored -> Option B
  4. Quick Check:

    Capacity ≠ Count; Capacity ≥ Count [OK]
Quick Trick: Capacity reserves space; Count counts items [OK]
Common Mistakes:
MISTAKES
  • Assuming Capacity equals Count
  • Thinking Capacity shrinks automatically
  • Confusing null elements with capacity

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes