Bird
Raised Fist0

Which statement best describes how LINQ method syntax handles duplicate keys when using ToDictionary?

hard🧠 Conceptual Q10 of Q15
C Sharp (C#) - LINQ Fundamentals
Which statement best describes how LINQ method syntax handles duplicate keys when using ToDictionary?
AIt automatically merges values of duplicate keys
BIt keeps the first key-value pair and ignores duplicates
CIt throws an exception if duplicate keys exist
DIt keeps the last key-value pair and overwrites duplicates
Step-by-Step Solution
Solution:
  1. Step 1: Understand ToDictionary behavior

    ToDictionary requires unique keys; duplicates cause errors.
  2. Step 2: Check handling of duplicates

    It throws an exception rather than merging or ignoring duplicates.
  3. Final Answer:

    It throws an exception if duplicate keys exist -> Option C
  4. Quick Check:

    ToDictionary duplicates cause exception [OK]
Quick Trick: ToDictionary needs unique keys or throws error [OK]
Common Mistakes:
MISTAKES
  • Assuming duplicates merge
  • Thinking duplicates are ignored
  • Believing last key overwrites silently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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