Bird
0
0

You need to maintain a list of usernames that can be updated by adding or removing entries at runtime. Which data structure is most suitable in C# and why?

hard🚀 Application Q8 of 15
C Sharp (C#) - Collections
You need to maintain a list of usernames that can be updated by adding or removing entries at runtime. Which data structure is most suitable in C# and why?
AString because it can hold multiple usernames separated by commas
BArray because it has fixed size and better performance
C<code>Dictionary<int, string></code> because it stores key-value pairs
D<code>List<string></code> because it supports dynamic resizing and easy modification
Step-by-Step Solution
Solution:
  1. Step 1: Consider dynamic updates

    The list must allow adding and removing usernames dynamically.
  2. Step 2: Evaluate options

    Arrays have fixed size; Dictionary is for key-value pairs; String is not suitable for collections.
  3. Final Answer:

    List<string> because it supports dynamic resizing and easy modification -> Option D
  4. Quick Check:

    Dynamic list fits changing data [OK]
Quick Trick: Use List for dynamic collections [OK]
Common Mistakes:
MISTAKES
  • Choosing arrays for dynamic data
  • Using string to store multiple values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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