• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >C#教程 > C#内置队列类Queue用法实例

C#内置队列类Queue用法实例

作者:八大山人 字体:[增加 减小] 来源:互联网 时间:2017-05-28

八大山人 通过本文主要向大家介绍了队列queue,java 队列 queue,c#queue,c#中dequeue,c#queue的用法等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了C#内置队列类Queue用法。分享给大家供大家参考。具体分析如下:

这里详细演示了C#内置的队列如何进行添加,移除等功能。

using System;
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
 */
</div>

希望本文所述对大家的C#程序设计有所帮助。

</div>
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • C#队列Queue多线程用法实例
  • C#队列Queue用法实例分析
  • C#内置队列类Queue用法实例
  • c#队列Queue学习示例分享

相关文章

  • 2017-05-28C# 7.0之ref locals and returns(局部变量和引用返回)
  • 2017-05-28C#实现根据银行卡卡号判断银行名
  • 2017-05-28C#模拟window操作鼠标的方法
  • 2017-05-28C#实现的AES加密解密完整实例
  • 2017-05-28遍历Hashtable 的几种方法
  • 2017-05-28C#通过流写入一行数据到文件的方法
  • 2017-05-28C#简单实现在网页上发邮件的案例
  • 2017-05-28学习Winform分组类控件(Panel、groupBox、TabControl)
  • 2017-05-28C#中判断一个集合是否是另一个集合的子集的简单方法
  • 2017-05-28c#中合并DataTable重复行的值

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • C#实现图形位置组合转换的方法
    • 用C#写的ADSL拨号程序的代码示例
    • 利用thrift实现js与C#通讯的实例代码
    • C#实现注册码的方法
    • FileStream常用的属性与方法总结
    • C#通过委托调用Button单击事件的方法
    • C#生成随机验证码代码分享
    • C#实现托盘程序并禁止多个应用实例运行的方法
    • c#使用filesystemwatcher监视文件系统的变化
    • c# 所有类型都从Object类型派生

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有