-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- using System;
- using System.Collections.Generic;
- class Program
- {
- static void Main(string[] args)
- {
-
- Queue<string> numbers = new Queue<string>();
- numbers.Enqueue("one");
- numbers.Enqueue("two");
- numbers.Enqueue("three");
- numbers.Enqueue("four");
- numbers.Enqueue("five");
-
- foreach (string s in numbers)
- {
- Console.WriteLine(s);
- }
-
- Console.WriteLine("\nDequeuing '{0}'", numbers.Dequeue());
- Console.WriteLine("Peek at next item to dequene:{0}", numbers.Peek());
- Console.WriteLine("Dequeuing '{0}'", numbers.Dequeue());
-
- string[] strArray = numbers.ToArray();
- Console.WriteLine("\n数组对象:");
- foreach (string s in strArray)
- {
- Console.WriteLine(s);
- }
-
- Queue<string> queueCopy = new Queue<string>(strArray);
- Console.WriteLine("\n由数组对象\"strArray\"创建的队列容器:");
- foreach (string s in queueCopy)
- {
- Console.WriteLine(s);
- }
-
- string[] Array2 = new string[numbers.Count * 2];
- numbers.CopyTo(Array2, 0);
-
- Queue<string> queueCopy2 = new Queue<string>(Array2);
- Console.WriteLine("\n由数组对象\"Array2\"创建的队列容器:");
- foreach (string s in queueCopy2)
- {
- Console.WriteLine(s);
- }
-
- Console.WriteLine("\nqueueCopy.Contains(\"four\")={0}",queueCopy.Contains("four"));
- Console.WriteLine("queueCopy清除前元素个数:" + queueCopy.Count);
- queueCopy.Clear();
- Console.WriteLine("queueCopy清除后元素个数:"+queueCopy.Count);
- Console.Read();
- }
- }
posted @
2013-05-31 15:35
于为
阅读(
802)
评论()
编辑
收藏
举报