C Sharp (C#) - CollectionsWhat happens if you try to add duplicate keys using a Dictionary initializer in C#?AThe last value for the duplicate key overwrites previous onesBRuntime exception is thrownCDuplicate keys are ignored silentlyDCompile-time error occursCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand Dictionary initializer behaviorDuplicate keys in initializer cause runtime exceptions, not compile errors.Step 2: Exception typeArgumentException is thrown at runtime when duplicate keys are added.Final Answer:Runtime exception is thrown -> Option BQuick Check:Duplicate keys cause runtime exception = D [OK]Quick Trick: Duplicate keys cause runtime exception, not overwrite [OK]Common Mistakes:MISTAKESAssuming last value overwrites silentlyExpecting compile-time errorThinking duplicates are ignored
Master "Collections" in C Sharp (C#)9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More C Sharp (C#) Quizzes Classes and Objects - Constructor overloading - Quiz 6medium Collections - List methods (Add, Remove, Find, Sort) - Quiz 6medium Inheritance - Base class and derived class - Quiz 7medium Interfaces - Default interface methods - Quiz 3easy Polymorphism and Abstract Classes - Type checking patterns - Quiz 9hard Polymorphism and Abstract Classes - Casting with as and is operators - Quiz 8hard Polymorphism and Abstract Classes - Runtime polymorphism execution - Quiz 3easy Polymorphism and Abstract Classes - Virtual method dispatch mechanism - Quiz 14medium Properties and Encapsulation - Auto-implemented properties - Quiz 6medium Strings and StringBuilder - String searching and extraction - Quiz 6medium