Bird
Raised Fist0

Which of the following is the correct way to declare a collection that can grow in size in C#?

easy📝 Syntax Q12 of Q15
C Sharp (C#) - Collections
Which of the following is the correct way to declare a collection that can grow in size in C#?
Aint[] numbers = new int[5];
BList<int> numbers = new List<int>();
Cint numbers = new List<int>();
DArrayList numbers = new int[5];
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax for array declaration

    int[] numbers = new int[5]; declares a fixed-size array, not a collection.
  2. Step 2: Check syntax for collection declaration

    List<int> numbers = new List<int>(); correctly declares a generic list collection that can grow.
  3. Final Answer:

    List<int> numbers = new List<int>(); -> Option B
  4. Quick Check:

    List<T> syntax is for growable collections [OK]
Quick Trick: Use List for growable collections, arrays need size upfront [OK]
Common Mistakes:
MISTAKES
  • Using array syntax when collection is needed
  • Assigning wrong types to variables
  • Confusing ArrayList with arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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