'Peek'에 해당되는 글 1건
- 2007/08/27 Queue Tutorial In C#
To add items to the Queue you useEnqueue method. This method takes an object of any type but to keep things simple lets just give it a string object:
Queue q = new Queue();
q.Enqueue("So");
q.Enqueue("This");
q.Enqueue("Is");
q.Enqueue("How");
q.Enqueue("Queues");
q.Enqueue("Work");
q.Enqueue("So");
q.Enqueue("This");
q.Enqueue("Is");
q.Enqueue("How");
q.Enqueue("Queues");
q.Enqueue("Work");
Viewing a Single Object Without Removing it From the Queue
You can use the Peak method to get the topmost object in the queue without removing it from the queue:
Console.WriteLine(qPeek());
Viewing All the Objects in the Queue Without Removing Them
You can read any of the data in the Queue by using an enumerator:
System.Collections.IEnumerator en = q.GetEnumerator();
while (en.MoveNext())
{
Console.Write(en.Current " ");
}
while (en.MoveNext())
{
Console.Write(en.Current " ");
}
Removing Items from the Queue
To pop an item from the Queue you can use theDequeue statement. This returns the topmost object of the queue.
while( q.Count > 0)
{
Console.Write(q.Dequeue " ");
}
{
Console.Write(q.Dequeue " ");
}

Prev

Rss Feed