队列Queue

     Queue对象类似于数据结构中的队列,先进先出(FIFO)。

    

/*
  Example11_10.cs illustrates the use of a Queue
*/

using System;
using System.Collections;

class Example11_10
{

  public static void Main()
  {

    // create a Queue object
    Queue myQueue = new Queue();

    // add elements to myQueue using the Enqueue() method
    myQueue.Enqueue("This");
    myQueue.Enqueue("is");
    myQueue.Enqueue("a");
    myQueue.Enqueue("test");

    // display the elements in myQueue
    foreach (string myString in myQueue)
    {
      Console.WriteLine("myString = " + myString);
    }

    // get the number of elements in myQueue using the
    // Count property
    int numElements = myQueue.Count;

    for (int count = 0; count < numElements; count++)
    {

      // examine an element in myQueue using Peek()
      Console.WriteLine("myQueue.Peek() = " +
        myQueue.Peek());

      // remove an element from myQueue using Dequeue()
      Console.WriteLine("myQueue.Dequeue() = " +
        myQueue.Dequeue());

    }

  }

}
原文地址:https://www.cnblogs.com/djcsch2001/p/2039427.html