You are developing an application that will store user messages collectively and the process the messages in sequence.
The order in which the messages are processed will depend on the order in which it is received.
To add messages to the collection, users will specify the message that should be stored in a TextBox control named txtMsg
and then click a Button control named btnAdd.
You need to ensure that the appropriate code is used to create the collection.
What should you use? (Choose two)
A.
Queue msgCollection = new Queue ();
B.
Stack msgCollection = new Stack ();
C.
msgCollection.Enqueue (txtMSG.Text);
D.
msgCollection.Push (txtMSG.Text);
Explanation:
In this scenario, you should use the Queue class to create the collection because you are required to process user messages in sequence. The Dim statement creates an object named msgCollection of the Queue class. The second line of code then calls the Enqueue method of the msgCollection object to add the Text property value of the txtMSG control as an element in the collection. To manage elements in the queue, the Queue class provides methods, such as Dequeue and Clear. The Dequeue method is used to remove elements that are at the beginning of the Queue object. The
Clear method is used to remove all elements from a Queue object. The Queue class is a data structure for handling elements based on the First In First Out (FIFO) concept.
Incorrect Answers:
B, D: Using these lines of code is incorrect because they use the Stack class to create a collection. Stack objects are used to store elements on the Last In First Out (LIFO) concept.
I choose AC