Programming in C# — Question 128
You need to store the values in a collection.
The solution must meet the following requirements:
✑ The values must be stored in the order that they were added to the collection.
✑ The values must be accessed in a first-in, first-out order.
Which type of collection should you use?
Answer options
- A. SortedList
- B. Queue
- C. ArrayList
- D. Hashtable
Correct answer: B
Explanation
The correct choice is B, Queue, as it is specifically designed for first-in, first-out access, maintaining the order of elements as they are added. A SortedList and Hashtable do not preserve the order of insertion, while an ArrayList allows for indexed access but does not enforce FIFO behavior.