Bird
0
0

You need to store a list of user names that can change during program execution. Which approach is best and why?

hard🚀 Application Q15 of 15
C Sharp (C#) - Collections
You need to store a list of user names that can change during program execution. Which approach is best and why?
AUse a List<string> because it can grow and shrink as users are added or removed.
BUse an array because it is faster and fixed size is enough.
CUse a fixed-size array and recreate it every time the list changes.
DUse a string variable to store all names separated by commas.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze data size flexibility needs

    User names list changes size, so fixed size arrays are inconvenient.
  2. Step 2: Choose collection type for dynamic data

    List<string> allows adding/removing names easily without recreating the structure.
  3. Final Answer:

    Use a List<string> because it can grow and shrink as users are added or removed. -> Option A
  4. Quick Check:

    Dynamic data needs collections like List [OK]
Quick Trick: Dynamic data? Use List for easy resizing [OK]
Common Mistakes:
MISTAKES
  • Choosing fixed arrays for changing data
  • Using strings to store multiple values unsafely
  • Recreating arrays repeatedly instead of collections

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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