.NET, ASP.NET, C#, VB.NET, SQL Server, WPF, XAML
Login
Articles
About Us
Submit Article
Check this
san san
replied to Jobi K John at 11-Aug-08 08:31
Hi
You can use Queue class available in Syatem.Collections namespace.
1. How to Create a Queue?
Queue q =
new
Queue(10);
10 is the intial size of the Queue. It is always better to give intially size so that the Insert/Remove operations are performed efficiently with out re-arranging the elements.
How to add an element to the Queue?
q.Enqueue(12);
Enqueue() will add an element to the Queue. The item is inserted at the last available position of the queue.
How to Remove an Element?
object
ob = q.Dequeue()
Dequeue() will return the element which is added very old and also removes the item from the Queue. It throws Exception when the Queue is Empty.
Take a look at this example:
// create a queue of capacity 10
System.Collections.Queue q = new System.Collections.Queue(10);
// check for queue count
// if count > 10 ,then delete from the begining.
if (q.Count > 10)
{
object data = q.Dequeue();
}
//then insert an element to the queue at end.
q.Enqueue("item 1");
hope this helps
SAN
Click here to sign in and reply. You could earn money via our $500 contest just for being helpful.
Help me - Jobi K John 07-May-08 01:17 1:17:43 PM
Well the Queue is a first in, first out collection, - Peter Bromberg 07-May-08 03:48 3:48:59 PM
Here you go - Vaibhav Gadodia 08-May-08 01:12 1:12:03 AM
Example - Sanjay Verma 08-May-08 07:03 7:03:18 AM
Re: - chakradhar koturu 08-May-08 10:23 10:23:31 PM
RE : - Swapnil Salunke 09-May-08 01:13 1:13:38 AM
Check this - san san 11-Aug-08 08:31 8:31:02 AM
View Posts