Click here to Skip to main content
12,890,181 members (42,739 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 12 Sep 2011

Queues Implemented with C#

, 12 Sep 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Queues Implemeted with C#

Queues are just like stacks, except that the objects collected by them are first in, first out (FIFO).

First, a Queue object needs to be declared and instantiated:

Queue theQueue = new Queue();

Here's the code to enqueue a string:

private void btnEnqueue_Click(object sender, System.EventArgs e) {
txtIn.Text = "";
foreach (string s in theQueue) {

Dequeuing is pretty much the same thing, although (as you'd suspect) a check needs to be added to see that there is actually something on the queue:

private void btnDequeue_Click(object sender, System.EventArgs e) {
if (theQueue.Count > 0) {
txtOut.Text = (string) theQueue.Dequeue();
foreach (string s in theQueue) {
MessageBox.Show("Nothing on the queue to dequeue!",
"No more waiting in line!", MessageBoxButtons.OK,


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer Standout IT Solutions(P) Ltd.
India India
My name is SuhasHaridas.

I'm a Software Engineer in the .NET Developer Platform group within the Developer Division at Standout IT Solutions(P) Ltd.
I have focused on the Web platform during these years.Specifically, that means I have worked on ASP.NET and c#.NET ,SharePoint,Sql, WCS Apps(Cisco Wireless Control System),.NET Compact Framework, LINQ , ADO.NET , entity framework ,Silverlight , WCF Services , SQL SQLCE Visual Studio and Visual Studio Web Developer as well as on IIS7.

You may also be interested in...


Comments and Discussions

GeneralReason for my vote of 1 This is the very basic, and useless. Pin
InTRUEdeR10-Oct-11 8:35
memberInTRUEdeR10-Oct-11 8:35 
GeneralReason for my vote of 1 I give you a 1 because there is no w... Pin
rmiguel21-Sep-11 3:16
memberrmiguel21-Sep-11 3:16 
GeneralReason for my vote of 1 Plagarism Pin
Marcus Kramer12-Sep-11 9:25
memberMarcus Kramer12-Sep-11 9:25 
GeneralReason for my vote of 5 Good job.... Pin
Pravin Patil, Mumbai12-Sep-11 8:21
memberPravin Patil, Mumbai12-Sep-11 8:21 
GeneralReason for my vote of 1 MSDN online doc is better. http://ms... Pin
mattypiper21-Dec-10 7:48
membermattypiper21-Dec-10 7:48 
GeneralReason for my vote of 1 Do not need MSDN copy Pin
_FleX20-Dec-10 20:20
member_FleX20-Dec-10 20:20 
GeneralReason for my vote of 5 My Vote 5 Pin
Abdul Quader Mamun17-Dec-10 5:13
memberAbdul Quader Mamun17-Dec-10 5:13 
GeneralReason for my vote of 2 Good basic article Pin
Ravi Teja P16-Dec-10 17:48
memberRavi Teja P16-Dec-10 17:48 
GeneralGood work Pin
Abdul Quader Mamun16-Dec-10 8:36
memberAbdul Quader Mamun16-Dec-10 8:36 
GeneralYou forgot to quote your source Pin
Indivara16-Dec-10 3:36
subeditorIndivara16-Dec-10 3:36 
GeneralReason for my vote of 5 Good Tip. Pin
Eswa16-Dec-10 0:26
memberEswa16-Dec-10 0:26 
GeneralReason for my vote of 5 good work Pin
ershad1215-Dec-10 16:53
memberershad1215-Dec-10 16:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170424.1 | Last Updated 12 Sep 2011
Article Copyright 2011 by SuhasHaridas
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid