-
C# Queue<>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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();
- }
- }
-
相关阅读:
Linux内核分析--系统调用【转】
Linux slab分配器【转】
简化指令与复杂指令的区别【转】
冯诺依曼体系结构与哈佛体系结构的区别【转】
bzero, memset ,setmem 区别【转】
写一个标准宏MIN,输入两个参数,返回较小的
红黑树(一)之原理和算法的详细分析【转】
socket心跳包机制总结【转】
Linux文件时间详解ctime、mtime、atime【转】
【转】图文并茂 Ubuntu使用Thunderbird方法指南
-
原文地址:https://www.cnblogs.com/ywsoftware/p/3110492.html
Copyright © 2020-2023
润新知