The Queue Collection

The System.Collections.Queue collection works according to the FIFO (First-In, First-Out) paradigm, meaning that the first item you add to the collection is the first pulled out from the collection. Queue exposes two methods, Enqueue that adds a new item to the collection and Dequeue that removes an item from the collection. Both methods receive an argument of type Object. The following code provides an example:

image

You just need to invoke the Dequeue method to consume and automatically remove an item from the collection. You can also invoke the Peek method which just returns the first item from the collection without removing it. Always be careful when adding items to a queue because you are working in a fashion that is not strongly typed. If you plan to work with objects of a specified type (for example, you need a collection of Integer), consider using a Queue(Of T) that behaves the same way except that it is strongly typed. The collection also exposes a Count property that returns the number of items in the collection. The constructor provides an overload that enables specifying the capacity for the collection.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.0.97