Bird
Raised Fist0

Which of the following is the correct way to declare a List of integers in C#?

easy📝 Syntax Q12 of Q15
C Sharp (C#) - Collections
Which of the following is the correct way to declare a List of integers in C#?
AList<int> numbers = new List<int>();
BList numbers = new List<int>();
CList<int> numbers = List<int>();
DList<int> numbers = new List();
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct List<T> syntax

    In C#, to declare a generic List, you must specify the type and use the new keyword with constructor.
  2. Step 2: Check each option for syntax correctness

    List numbers = new List(); correctly declares and initializes a List of int. Others miss type, constructor, or use wrong syntax.
  3. Final Answer:

    List numbers = new List(); -> Option A
  4. Quick Check:

    Generic List declaration = new List<T>() [OK]
Quick Trick: Use new List() with type specified [OK]
Common Mistakes:
MISTAKES
  • Omitting new keyword
  • Not specifying generic type in constructor
  • Using non-generic List without type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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