Programming in C# — Question 143

You are developing an application that contains a class named TheaterCustomer and a method named ProcessTheaterCustomer. The method accepts a TheaterCustomer object as the input parameter.
ProcessTheaterCustomer()
You have the following requirements:
✑ Store the TheaterCustomer objects in a collection.
✑ Ensure that the ProcessTheaterCustomer() method processes the TheaterCustomer objects in the reverse order in which they are placed into the collection.
You need to meet the requirements.
What should you do?

Answer options

Correct answer: C

Explanation

The correct answer is C because a Stack collection processes objects in a Last In, First Out (LIFO) manner, which aligns with the requirement to process TheaterCustomer objects in reverse order. Option A is incorrect as a Queue processes objects in a First In, First Out (FIFO) manner, while Option B does not provide a way to remove items in reverse order. Option D also fails to meet the requirements since Peek() does not remove objects from the collection.