Bird
0
0

Which of the following is the correct syntax to initialize a List of integers with values 1, 2, and 3?

easy📝 Syntax Q3 of 15
C Sharp (C#) - Collections
Which 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);
Step-by-Step Solution
Solution:
  1. Step 1: Review collection initialization syntax

    Correct syntax uses braces with comma-separated values inside after new List<int>.
  2. Step 2: Check each option

    var list = new List {1, 2, 3}; matches this syntax; others use invalid constructors or methods.
  3. Final Answer:

    var list = new List<int> {1, 2, 3}; -> Option C
  4. Quick Check:

    List initialization syntax = braces with values [OK]
Quick Trick: Use braces {} with values to initialize collections [OK]
Common Mistakes:
MISTAKES
  • Using parentheses instead of braces
  • Trying to call Add method during initialization

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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