//队列 private void button12_Click(object sender, EventArgs e) { //声明队列 队列,先进先出 List就是个链表,不是先进先出。 Queue q = new Queue(); //添加到队列 q.Enqueue('A'); q.Enqueue('B'); q.Enqueue('C'); q.Enqueue('D'); q.Enqueue('E'); Console.WriteLine("cureent queue:"); foreach (char c in q) { Console.Write(c + " "); } Console.WriteLine(); q.Enqueue('V');//向 Queue 的末尾添加一个对象。 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();//移除并返回在 Queue 的开头的对象。 Console.WriteLine("The removed value: {0}", ch); ch = (char)q.Dequeue(); Console.WriteLine("The removed value: {0}", ch); Console.WriteLine("获取队列的个数: {0}", q.Count); Console.WriteLine("判断一个元素是否在队列中", q.Contains("A")); //清空整个队列 q.Clear() }