Skip to Main Content
C# in a Nutshell
book

C# in a Nutshell

by Ben Albahari, Ted Neward, Peter Drayton
March 2002
Intermediate to advanced content levelIntermediate to advanced
864 pages
31h 8m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell

Name

Queue

Synopsis

This class describes a collection manipulated on a first-in, first-out basis. The newest elements are added to one end with the Enqueue() method, and the oldest are taken off the other end with Dequeue(). A Queue can be constructed as an empty collection or with the elements of an existing collection. The initial capacity can also be specified, although the default for an empty queue is 32. Normally, a Queue automatically increases its capacity when new elements exceed the current capacity, using a default growth factor of 2.0. (The growth factor is multiplied by the current capacity to determine the new capacity.) You may specify your own growth factor when you specify an initial capacity for the Queue.

The Dequeue() method returns the element at the beginning of the Queue, and simultaneously removes it. You can get the first element without removal by using Peek(). The contents of a Queue can be copied to an existing Array object using the CopyTo() method. ToArray() creates a new Array object with the contents of the Queue.

The Queue is not threadsafe. The Synchronize() method provides a wrapper for thread safety.

public class Queue : ICollection, IEnumerable, ICloneable {
// Public Constructors
   public method Queue();  
   public method Queue(ICollection col);  
   public method Queue(int capacity);  
   public method Queue(int capacity, float growFactor);  
// Public Instance Properties
   public virtual field int Count{get; }                         // implements ICollection public virtual field bool ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# 8.0 in a Nutshell

C# 8.0 in a Nutshell

Joseph Albahari, Eric Johannsen
C# 10 in a Nutshell

C# 10 in a Nutshell

Joseph Albahari
C# in a Nutshell, Second Edition

C# in a Nutshell, Second Edition

Peter Drayton, Ben Albahari, Ted Neward
Code like a Pro in C#

Code like a Pro in C#

Jort Rodenburg

Publisher Resources

ISBN: 0596001819Catalog PageErrata