Bird
0
0

Find the error in this dictionary initialization:

medium📝 Debug Q7 of 15
C Sharp (C#) - Collections
Find the error in this dictionary initialization:
var dict = new Dictionary { "a" = 1, "b" = 2 };
AUse comma ',' instead of equals '=' for key-value pairs
BKeys must be integers, not strings
CDictionary cannot be initialized with values
DMissing parentheses after Dictionary type
Step-by-Step Solution
Solution:
  1. Step 1: Review dictionary initialization syntax

    Key-value pairs use braces with comma-separated pairs, each pair uses braces with comma, not equals.
  2. Step 2: Identify syntax error

    Equals sign '=' is invalid; correct syntax uses braces {"a", 1}.
  3. Final Answer:

    Use comma ',' instead of equals '=' for key-value pairs -> Option A
  4. Quick Check:

    Dictionary key-value pairs use braces or comma, not equals [OK]
Quick Trick: Use braces {key, value} for dictionary pairs [OK]
Common Mistakes:
MISTAKES
  • Using '=' instead of proper syntax for key-value pairs
  • Confusing dictionary initialization with object initializer

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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