Programming Tutorials

Queue data structure in VB.net

By: Issac in VB.net Tutorials on 2009-01-30  

In VB.NET, you can implement a queue data structure using the Queue class. Here's an example:

Dim queue As New Queue()

' Adding items to the queue
queue.Enqueue("apple")
queue.Enqueue("banana")
queue.Enqueue("cherry")

' Removing items from the queue
Dim item1 As String = queue.Dequeue()
Dim item2 As String = queue.Dequeue()

' Displaying the remaining items in the queue
For Each item As String In queue
    Console.WriteLine(item)
Next

In this example, we first create a new Queue object. We then add three items to the queue using the Enqueue method. Next, we remove two items from the queue using the Dequeue method, which removes and returns the item at the beginning of the queue. Finally, we loop through the remaining items in the queue and display them using a For Each loop.






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in VB.net )

Latest Articles (in VB.net)