C Sharp (C#) - CollectionsWhich of the following is the correct syntax to initialize a List of integers with values 1, 2, and 3?Avar list = new List<int>[1, 2, 3];Bvar list = new List<int>(1, 2, 3);Cvar list = new List<int> {1, 2, 3};Dvar list = new List<int>.Add(1, 2, 3);Check Answer
Step-by-Step SolutionSolution:Step 1: Review collection initialization syntaxCorrect syntax uses braces with comma-separated values inside after new List<int>.Step 2: Check each optionvar list = new List {1, 2, 3}; matches this syntax; others use invalid constructors or methods.Final Answer:var list = new List<int> {1, 2, 3}; -> Option CQuick Check:List initialization syntax = braces with values [OK]Quick Trick: Use braces {} with values to initialize collections [OK]Common Mistakes:MISTAKESUsing parentheses instead of bracesTrying to call Add method during initialization
Master "Collections" in C Sharp (C#)9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More C Sharp (C#) Quizzes Classes and Objects - Object instantiation with new - Quiz 8hard Classes and Objects - Constructor overloading - Quiz 3easy Exception Handling - Why exception handling is needed - Quiz 12easy File IO - Why file operations matter - Quiz 2easy File IO - File paths and Directory operations - Quiz 3easy File IO - Using statement with file streams - Quiz 12easy Inheritance - Why inheritance is needed - Quiz 4medium Interfaces - Interface vs abstract class decision - Quiz 8hard Interfaces - Implementing interfaces - Quiz 6medium Properties and Encapsulation - Read-only and write-only properties - Quiz 7medium