Queue Tutorial In C#

 
 
To add items to the Queue you use Enqueue method. This method takes an object of any type but to keep things simple lets just give it a string object:
 
 
  1. Adding Items to the Queue

  2. To add items to the Queue you use Enqueue method. This method takes an object of any type but to keep things simple lets just give it a string object:

  3.  

  4. Queue q = new Queue();

  5.  

  6. q.Enqueue("So");

  7. q.Enqueue("This");

  8. q.Enqueue("Is");

  9. q.Enqueue("How");

  10. q.Enqueue("Queues");

  11. q.Enqueue("Work");

  12.  

  13.  

  14.  

  15. Viewing a Single Object Without Removing it From the Queue

  16. You can use the Peak method to get the topmost object in the queue without removing it from the queue:

  17.  

  18. Console.WriteLine(q.Peek());

  19.  

  20.  

  21.  

  22. Viewing All the Objects in the Queue Without Removing Them

  23. You can read any of the data in the Queue by using an enumerator:

  24.  

  25. System.Collections.IEnumerator en = q.GetEnumerator();

  26.  

  27. while (en.MoveNext())

  28. {

  29.    Console.Write(en.Current   " ");

  30. }

  31.  

  32.  

  33.  

  34. Removing Items from the Queue

  35. To pop an item from the Queue you can use the Dequeue statement. This returns the topmost object of the queue.

  36.  

  37. while( q.Count > 0)

  38. {

  39.    Console.Write(q.Dequeue   " ");

  40. }

  41.  

  42.  
 
Copy to Clipboard      Download code as Text Format
 
  Date entered : 12th Jun 2007
  Rating : No Rating
  Accessed  :  3741
  Submitted by :  mobeenamjad
 
   Add Comment  Printer friendly
   View All Comments  Email to a friend
   Add to my Favourites Download PDF version
   Rating  
 
                 Click each image to add
this page to each site.
 
 
 
Comments Available

    No comment available at the moment.Be the first one to make a comment

 
Related C# Source Codes
Database error: Invalid SQL: select FLOOR( AVG(b.rating)) as avg_rating,a.sourcecode_id sourcecode_id ,title,description,author,category_id,skill_level,reference,reference_mail,reference_url,a.user_id user_id,date_entered,source,accessed,dev_id,file_url,total_comments,instruction,registered,authorised,fld_deletemark,fld_code_version,fld_searchkeyword,fld_code_status,category_id from tbl_sourcecode a LEFT JOIN tbl_sourcecodecomment b ON a.sourcecode_id = b.sourcecode_id LEFT JOIN tbl_codecategory c ON a.category_id = c.fld_categoryID where a.fld_deletemark = 'N' AND a.fld_enable_disable= 'Y' AND a.authorised='Y' AND c.fld_groupIDFK='13' AND a.sourcecode_id!='2843' GROUP BY a.sourcecode_id order by a.sourcecode_id DESC limit 0, 5
MySQL Error: 1030 (Got error 122 from storage engine)
Session halted.
Warning: Unknown(): write failed: Disk quota exceeded (122) in Unknown on line 0

Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0