示例
以下示例演示了概念-
using System;
using System.Collections;
namespace CollectionsApplication {
class Program {
static void Main(string[] args) {
Queue q = new Queue();
q.Enqueue('A');
q.Enqueue('M');
q.Enqueue('G');
q.Enqueue('W');
Console.WriteLine("Current queue: ");
foreach (char c in q) Console.Write(c + " ");
Console.WriteLine();
q.Enqueue('V');
q.Enqueue('H');
Console.WriteLine("Current queue: ");
foreach (char c in q) Console.Write(c + " ");
Console.WriteLine();
Console.WriteLine("Removing some values ");
char ch = (char)q.Dequeue();
Console.WriteLine("The removed value: {0}", ch);
ch = (char)q.Dequeue();
Console.WriteLine("The removed value: {0}", ch);
Console.ReadKey();
}
}
}
尝试一下
编译并执行上述代码后,将产生以下结果-
Current queue:
A M G W
Current queue:
A M G W V H
Removing values
The removed value: A
The removed value: M