Bird
Raised Fist0

Why does collection initialization syntax require the collection to have an Add method?

hard🧠 Conceptual Q10 of Q15
C Sharp (C#) - Collections
Why does collection initialization syntax require the collection to have an Add method?
ABecause Add sorts the collection automatically
BBecause Add is used to remove elements after initialization
CBecause Add converts the collection to an array
DBecause the compiler calls Add to insert each element during initialization
Step-by-Step Solution
Solution:
  1. Step 1: Understand how collection initialization works

    The compiler translates collection initialization into calls to the Add method for each element.
  2. Step 2: Evaluate options

    Because the compiler calls Add to insert each element during initialization correctly explains the role of Add; others describe unrelated behaviors.
  3. Final Answer:

    Because the compiler calls Add to insert each element during initialization -> Option D
  4. Quick Check:

    Collection initialization uses Add method internally [OK]
Quick Trick: Add method is called for each item during collection initialization [OK]
Common Mistakes:
MISTAKES
  • Thinking Add removes or sorts elements
  • Assuming Add converts collections to arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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