O'Reilly logo

Learning Visual Basic .NET by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Queues

A queue represents a first-in first-out (FIFO) collection. The classic analogy is a line (or queue if you are British) at a ticket window. The first person to get in the line ought to be the first person to come off the line to buy a ticket.

The Queue class is a good collection to use when you are managing a limited resource. For example, you might want to send messages to a resource that can handle only one message at a time. You would then create a message queue so that you can say to your clients: "Your message is important to us. Messages are handled in the order in which they are received."

The Queue class has a number of member methods and properties, the most important of which are shown in Table 15-4.

Table 15-4. Queue members

Method or property

Purpose

Count

Public property that gets the number of elements in the Queue

Clear( )

Method that removes all objects from the Queue

Contains( )

Method that determines if an element is in the Queue

CopyTo( )

Method that copies the Queue elements to an existing one-dimensional array

Dequeue( )

Method that removes and returns the object at the beginning of the Queue

Enqueue( )

Method that adds an object to the end of the Queue

GetEnumerator( )

Method that returns an enumerator for the Queue

Peek( )

Method that returns the object at the beginning of the Queue without removing it

ToArray( )

Method that copies the elements to a new array

Add elements to your queue with the Enqueue( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required