Subscribe

RSS Feed (xml)

ASP.NET Queue Collection

Create a new object of type


System.Collections.Queue called myQueue. Add items to


the queue by using the EnQueue method and passing in the object you want to add to


the queue.You can then retrieve items from the front of the queue (remember a queue


is first-in-first-out, or FIFO) by using the DeQueue method.The item is returned as type


of object, so if you need to convert it into a string as in the following example, you simply


call the ToString() method. Otherwise, you'll need to cast it to the type of object


that you need.


In <script runat="server" /> block or codebehind:


'Make sure System.Collections is imported


Sub Page_Load(sender As Object, e As EventArgs)


Dim myQueue As New Queue()


myQueue.Enqueue("One")


myQueue.Enqueue("Two")


myQueue.Enqueue("Three")


While myQueue.Count > 0


Response.Write(myQueue.Dequeue().ToString() & "<br>")


End While


End Sub

No comments:

Variety in the Web World