You are developing an application that makes use of a Queue class object named MyQueue.
This Queue class object will be used to store messages sent by the user during application run time.
You would like to access the message at the beginning of the queue, prior to processing the user messages, without removing it.
What should you do?
A.
Use the Enqueue method of the MyQueue object.
B.
Use the Contains method of the MyQueue object.
C.
Use the Dequeue method of the MyQueue object.
D.
Use the Peek method of the MyQueue object.
Explanation:
The Peek method accesses the element at the beginning of the object of the Queue class without removing it from the queue. The Queue class is a data structure for handling elements based on the First In First Out (FIFO) concept. According to this concept, elements that are stored first are processed first.
Incorrect Answers:
A: You should not use this method of the Queue class because it is used to add a new element at the end of a Queue object.
B: You should not use this method of the Queue class because it is used to verify whether the specified element exists for the Queue object instance or not.
C: You should not use this method of the Queue
class because it is used to remove the next element at the beginning of a Queue object.
I choose D