VB.NET-INFORMATIONS.COM

<< Back To - VB.NET Collections Tutorials

How to VB.Net Queue

Vb.Net Help      Crystal Reports      Excel


The Queue is another adtastructure from VB.NET Collections . It works like FIFO system. That is First In First Out, The item added in Queue is , first get out from Queue. We can Enqueue (add) items in Queue and we can Dequeue (remove from Queue ) or we can Peek (that is get the reference of first item added in Queue ) the item from Queue.

The commonly using functions are follows :

Enqueue : Add an Item in Queue

Syntax : Stack.Enqueue(Object)

Object : The item to add in Queue

Dequeue : Remove the oldest item from Queue (we dont get the item later)

Syntax : Stack.Dequeue()

Returns : Remove the oldest item and return.

Peek : Get the reference of the oldest item (it is not removed permenantly)

Syntax : Stack.Peek()

returns : Get the reference of the oldest item in the Queue

The following VB.NET Source code shows some of commonly used functions :

VB.NET SourceCode

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object,_
	ByVal e As System.EventArgs) Handles Button1.Click
        Dim queueList As New Queue
        queueList.Enqueue("Sun")
        queueList.Enqueue("Mon")
        queueList.Enqueue("Tue")
        queueList.Enqueue("Wed")
        queueList.Enqueue("Thu")
        queueList.Enqueue("fri")
        queueList.Enqueue("Sat")
        MsgBox(queueList.Dequeue())
        MsgBox(queueList.Peek())
        If queueList.Contains("Sun") Then
            MsgBox("Contains Sun ")
        Else
            MsgBox("Not Contains Sun ")
        End If
    End Sub
End Class
When you execute the program it add seven items in the Queue. Then it Dequeue (remove) the oldest item from queue. Next it Peek() the oldest item from Queue (shows only , not remove ). Next it check the Item "Sun" contains in the Queue.

VB.NET Collections Related Contents
How to use VB.NET ArrayList
How to use VB.NET HashTable
How to use VB.NET Stack
How to use VB.NET Arrays
How to use VB.NET Dyanamic Arrays
How to use VB.NET NameValueCollection

Search here for more Vb.Net Source Code :



    Categories

    HOME
    VB.NET

 
 
 
   













  |  Home   |  SiteMap   |  About   |
net-informations.com (C) 2008 All Rights Reserved