Queue)) 类,msdn上的一篇文章,便于查看
程序集: System(在 System.dll 中)
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
[ComVisibleAttribute(false)]
public class Queue<T> : IEnumerable<T>, ICollection,
IEnumerable
类型参数
- T
-
指定队列中元素的类型。
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
队列在按接收顺序存储消息方面非常有用,以便于进行顺序处理。存储在 Queue<(Of <(T>)>) 中的对象在一端插入,从另一端移除。
Queue<(Of <(T>)>) 的容量是指 Queue<(Of <(T>)>) 可以容纳的元素数。当向 Queue<(Of <(T>)>) 添加元素时,将通过重新分配内部数组,根据需要自动增大容量。可通过调用 TrimExcess 来减少容量。
Queue<(Of <(T>)>) 接受 nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing) 作为引用类型的有效值并且允许有重复的元素。
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
下面的代码示例演示了 Queue<(Of <(T>)>) 泛型类的几个方法。此代码示例创建一个具有默认容量的字符串队列,并使用 Enqueue 方法对五个字符串进行排队。枚举队列元素,这不会更改队列的状态。使用 Dequeue 方法使第一个字符串出列。使用 Peek 方法查找队列中的下一项,然后使用 Dequeue 方法使该项出列。
使用 ToArray 方法创建一个数组并将队列元素复制到该数组,然后将该数组传递给接受 IEnumerable<(Of <(T>)>) 的 Queue<(Of <(T>)>) 构造函数以创建队列副本。将显示副本的元素。
创建一个大小是队列大小两倍的数组,并使用 CopyTo 方法从数组中间开始复制数组元素。再次使用 Queue<(Of <(T>)>) 构造函数创建第二个队列副本,此队列在开始处包含三个 null 元素。
使用 Contains 方法显示字符串“four”在第一个队列副本中,然后使用 Clear 方法清除此副本并由 Count 属性显示该队列为空。
using System.Collections.Generic;
class Example
{
public static void Main()
{
Queue<string> numbers = new Queue<string>();
numbers.Enqueue("one");
numbers.Enqueue("two");
numbers.Enqueue("three");
numbers.Enqueue("four");
numbers.Enqueue("five");
// A queue can be enumerated without disturbing its contents.
foreach( string number in numbers )
{
Console.WriteLine(number);
}
Console.WriteLine("\nDequeuing '{0}'", numbers.Dequeue());
Console.WriteLine("Peek at next item to dequeue: {0}",
numbers.Peek());
Console.WriteLine("Dequeuing '{0}'", numbers.Dequeue());
// Create a copy of the queue, using the ToArray method and the
// constructor that accepts an IEnumerable<T>.
Queue<string> queueCopy = new Queue<string>(numbers.ToArray());
Console.WriteLine("\nContents of the first copy:");
foreach( string number in queueCopy )
{
Console.WriteLine(number);
}
// Create an array twice the size of the queue and copy the
// elements of the queue, starting at the middle of the
// array.
string[] array2 = new string[numbers.Count * 2];
numbers.CopyTo(array2, numbers.Count);
// Create a second queue, using the constructor that accepts an
// IEnumerable(Of T).
Queue<string> queueCopy2 = new Queue<string>(array2);
Console.WriteLine("\nContents of the second copy, with duplicates and nulls:");
foreach( string number in queueCopy2 )
{
Console.WriteLine(number);
}
Console.WriteLine("\nqueueCopy.Contains(\"four\") = {0}",
queueCopy.Contains("four"));
Console.WriteLine("\nqueueCopy.Clear()");
queueCopy.Clear();
Console.WriteLine("\nqueueCopy.Count = {0}", queueCopy.Count);
}
}
/* This code example produces the following output:
one
two
three
four
five
Dequeuing 'one'
Peek at next item to dequeue: two
Dequeuing 'two'
Contents of the copy:
three
four
five
Contents of the second copy, with duplicates and nulls:
three
four
five
queueCopy.Contains("four") = True
queueCopy.Clear()
queueCopy.Count = 0
*/
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
System.Collections.Generic..::.Queue<(Of <(T>)>)
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
此类型的公共静态(在 Visual Basic 中为 Shared)成员是线程安全的。但不能保证任何实例成员是线程安全的。
只要不修改该集合,Queue<(Of <(T>)>) 就可以同时支持多个阅读器。即便如此,从头到尾对一个集合进行枚举本质上并不是一个线程安全的过程。若要确保枚举过程中的线程安全,可以在整个枚举过程中锁定集合。若要允许多个线程访问集合以进行读写操作,则必须实现自己的同步。
文章摘自
转载于:https://www.cnblogs.com/0633shj/archive/2008/11/21/1338403.html
Queue)) 类,msdn上的一篇文章,便于查看相关推荐
- 如何在hexo上创建一篇文章
博客已经搭建好了,虽然功能比较少,但是还是可以写文章的 新建文章 使用命令来新建文章 hexo new [layout] <title> layout 是文章的布局,默认为post,可以先 ...
- node 后台文章编辑器_我如何使用Node从报纸网站上刮掉7000篇文章
node 后台文章编辑器 我为什么要这样做? (Why did I do this?) My girlfriend is writing a paper about the perception of ...
- 如何在arXiv上发表一篇文章
前言: 对于科研新人来说,有时候有一些好的想法不能第一时间通过正式的论文发表出来,便可以借助arXiv这个平台发表.这篇文章将简单介绍arXiv,并详细介绍如何在arXiv提交一篇论文. 关于arXi ...
- 自己真正意义上的第一篇文章(闲扯)
人的一生,绝大多数的东西都是带不走的,但,自己却想为人类留下一点可能有用的东西. 介绍一下自己 一位从小就热爱计算机.充满惊奇的.CS专业的大三学生,自己小学二年级无意间接触到计算机,就觉得好神奇,以 ...
- 近来发在CSDN畅言上的几篇文章
做个记录,免得日后找不到: [畅言]技术人,不要总在很初级的层面上谈管理 [畅言]流量变现--社交问答网站的生与死 [畅言]不把C作为第一门语言是个好主意么? [畅言]企业号会是微信的滑铁卢么? [畅 ...
- 如果有人问你数据库的原理,叫他看这篇文章
http://blog.jobbole.com/100349 一提到关系型数据库,我禁不住想:有些东西被忽视了.关系型数据库无处不在,而且种类繁多,从小巧实用的 SQLite 到强大的 Teradat ...
- 如果有人问你数据库的原理,看这篇文章。(超长预警)
长文,相当的通透.以下为scrat进行总结后的删减版. 下面假定你已经知道时间复杂度 关系型数据库无处不在,而且种类繁多,从小巧实用的 SQLite 到强大的 Teradata .但很少有文章讲解数据 ...
- 博客园写的第一篇文章
09年5月21号,cnblogs.com上的第一篇文章. 07年计算机专业毕业到现在已经工作两年了,一直对软件开发者充满了敬仰.自己一直也在向这个方向努力,高等教育的现实的脱节,不是谁的错,在学校唯有 ...
- 单基因gsea_这篇3+分核心基因筛选,点个在看,我们复现这篇文章!
今天和大家分享的是2019年11月发表在Frontiers in Genetics(IF:3.517)上的一篇文章,"Identifying Key Genes and Functional ...
最新文章
- ajax invoke error,配置全局的异常捕获时,走ajax请求下面报错
- have sb do / have sb doing / have sth dong 区别
- 1.什么是数据化运营——《数据挖掘与数据化运营实战》
- 最新OpenSSL漏洞CCS注入及升级修复
- C++ Primer 5 CH4 表达式
- 第15课 比尔庄园 《小学生C++趣味编程》
- 【报告分享】2021年BrandGrow中国新锐品牌增长潜力报告.pdf(附下载链接)
- 【shell 脚本】删除/var/log 下的日志
- 【易实战】Spring Cloud Greenwich Eureka:服务注册与发现
- 计算机上显示找不到无线网络连接,笔记本没有无线网络连接怎么办 解决方法介绍【图解】...
- WWW 2022 推荐系统和广告相关论文整理分类
- 网上商城所需软硬件架构分析
- 让星星⭐月亮告诉你,打印完全格式的日期格式 包含 年月日时分秒毫秒
- KSO-Linux下Centos7.5防火墙开放某个端口号权限
- windows双系统如何删除ubuntu系统并重装
- H5企业微信如何返回到菜单页?
- 人民币小写转换为大写
- 攻防世界-看雪看雪看雪
- android view 曝光,Android 曝光采集(商品view曝光量的统计)第二弹
- JavaScript竞彩篮球投注,注数和最高奖金的算法
热门文章
- java把一个list_java 把一个大list分成N个小list,然后用map存储的小方法
- java中label数值_java – 如何在JLabel中显示变量值
- python开三次方_python实现三次样条插值
- java 网络编程 聊天_Java——网络编程(实现基于命令行的多人聊天室)
- mc服务器音乐文件夹在哪,添加自定义音乐图文教程 我的世界怎么添加音乐
- linux 查看cpu
- 【ruoyi】java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoo
- 【Centos 8】【Centos 7】安装 docker
- markdown中添加锚点
- oracle查看执行最慢与查询次数最多的sql语句