c#queue

C#Queue.CopyTo()方法 (C# Queue.CopyTo() method)

Queue.CopyTo() method is used to copy the Queue elements/objects to an existing array from specified index.

Queue.CopyTo()方法用于将Queue元素/对象从指定的索引复制到现有数组。

Syntax:

句法:

    void Queue.CopyTo(Array, Int32);

Parameters: Array – Targeted array_name in which we have to copy the queue elements/objects, Int32 – is an index in targeted array_name from where queue elements/objects are copied.

参数: Array –我们必须在其中复制队列元素/对象的目标array_name , Int32 –是目标array_name中从中复制队列元素/对象的索引。

Return value: void – it returns nothing.

返回值: void –不返回任何内容。

Example:

例:

    declare and initialize a Queue:
Queue que = new Queue();
insertting elements:
que.Enqueue(100);
que.Enqueue(200);
que.Enqueue(300);
que.Enqueue(400);
que.Enqueue(500);
using CopyTo(), copying queue elements to the array:
que.CopyTo(arr, 3); //will copy from 3rd index in array
Output:
arr: 0 0 0 100 200 300 400 500 0 0 0 0 0 0 0 0 0 0 0 0

使用Queue.CopyTo()方法将队列元素/对象复制到数组的C#示例 (C# example to copy queue elements/objects to an array using Queue.CopyTo() method)

using System;
using System.Text;
using System.Collections;
namespace Test
{class Program
{//function to print queue elements
static void printQueue(Queue q)
{foreach (Object obj in q)
{Console.Write(obj + " ");
}
Console.WriteLine();
}
static void Main(string[] args)
{//declare and initialize a Queue
Queue que = new Queue();
//an array declaration for 20 elements
int[] arr = new int[20];
//insertting elements
que.Enqueue(100);
que.Enqueue(200);
que.Enqueue(300);
que.Enqueue(400);
que.Enqueue(500);
//printing Queue elements
Console.WriteLine("Queue elements...");
printQueue(que);
//printing array
Console.WriteLine("Array elements before CopyTo()...");
foreach (int item in arr)
{Console.Write(item + " ");
}
Console.WriteLine();
//using CopyTo(), copying Queue elements to the array
que.CopyTo(arr, 3);
//printing array
Console.WriteLine("Array elements after CopyTo()...");
foreach (int item in arr)
{Console.Write(item + " ");
}
Console.WriteLine();
//hit ENTER to exit
Console.ReadLine();
}
}
}

Output

输出量

Queue elements...
100 200 300 400 500
Array elements before CopyTo()...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Array elements after CopyTo()...
0 0 0 100 200 300 400 500 0 0 0 0 0 0 0 0 0 0 0 0

Reference: Queue.CopyTo(Array, Int32) Method

参考: Queue.CopyTo(Array,Int32)方法

翻译自: https://www.includehelp.com/dot-net/queue-copyto-method-with-example-in-c-sharp.aspx

c#queue

c#queue_带有C#示例的Queue.CopyTo()方法相关推荐

  1. python中 math.isfinite返回值为false_带有Python示例的math.isfinite()方法

    Python math.isfinite() 方法 math.isfinite()方法是数学模块的一种库方法,用于检查给定数字是否为非有限数,它接受数字(整数/浮点数,有限,无限或NaN),如果数字既 ...

  2. python中math.ceil是什么意思_带有Python示例的math.ceil()方法

    Python math.ceil() 方法 math.ceil()方法是数学模块的库方法,用于获取给定数字的ceil值,它接受数字/数字表达式并返回大于该数字的最小整数值. 注意:如果数字是整数值,则 ...

  3. math求旋转角度 python_带有Python示例的math.degrees()方法

    Python math.degrees() 方法 math.degrees()方法是数学模块的一种库方法,用于将角度值从弧度转换为度,它接受一个数字并返回以度为单位的角度值. 注意: math.deg ...

  4. python教程cos_带有Python示例的math.cos()方法

    Python math.cos() 方法 math.cos()方法是数学模块的库方法,用于获取弧度数的余弦值,它接受一个数字,返回给定弧度的余弦值. 注意: math.cos()方法接受的唯一的号码, ...

  5. python math.sinh_带有Python示例的math.sinh()方法

    Python math.sinh() 方法 math.sinh()方法是数学模块的一种库方法,用于获取以弧度为单位的给定数字的双曲正弦值,它接受一个数字并返回双曲正弦值. 注意: math.sinh( ...

  6. math.trunc_带有Python示例的math.trunc()方法

    math.trunc Python math.trunc()方法 (Python math.trunc() method) math.trunc() method is a library metho ...

  7. np.isfinite_带有Python示例的math.isfinite()方法

    np.isfinite Python math.isfinite()方法 (Python math.isfinite() method) math.isfinite() method is a lib ...

  8. factorial函数_带有Python示例的math.factorial()方法

    factorial函数 Python math.factorial()方法 (Python math.factorial() method) math.factorial() method is a ...

  9. python独立log示例_带有Python示例的math.log()方法

    python独立log示例 Python math.log()方法 (Python math.log() method) math.log() method is a library method o ...

最新文章

  1. 查某个类是否实现了某个协议
  2. 简单计算机面试题库及答案_460道Java后端面试高频题答案版【模块六:计算机操作系统】...
  3. 权限分配界面 纯手工 仅用到bootstrap的架构 以及 c标签
  4. spring+log4j
  5. 安卓案例:利用下拉列表选择科目
  6. 怎么编程安装字体文件
  7. 运营商大数据有哪些好处
  8. 实施工程师面试基本问题
  9. 分治法--线性时间选择
  10. word2016如何插入目录以及页码
  11. 计算机用户没有管理员权限,电脑没有管理员权限怎么办
  12. sql注入学习笔记1
  13. 在 linux 下如何解压扩展名为 xz 的文件
  14. 基于C++实现考试报名系统
  15. android 蓝牙自动断开,Android蓝牙:连接()/断开()
  16. Android: Switch更改颜色
  17. 修改Linux中发送邮件中附件大小的限制
  18. 今天,昆山向全世界发出邀请!
  19. 【滤波跟踪】基于粒子群算法优化粒子滤波实现目标滤波跟踪优化问题附matlab代码
  20. 叶胜超:IOST ----基于分片技术的第四大公链项目!

热门文章

  1. python拟合函数_Python-最小二乘法曲线拟合
  2. oracle sql 查询优化器,基于ORACLE成本优化器的SQL查询优化分析与应用
  3. python邮箱爆破_Python在线爆破邮箱账号密码测试代码(亲测可用)
  4. docker run 挂载卷_docker mysql配置挂载到卷
  5. springboot能用python吗_Python与springboot的对接
  6. alter table add column多个字段_ElementUI表格el-table表头固定自适应高度解决方案
  7. Python二级笔记(18,19合集操作篇)
  8. oracle常用表查询,ORACLE EBS常用表及查询语句(最终整理版)
  9. XMLHttpRequest+WebForm模式(接口IHttpHandler)实现ajax
  10. Gamma阶段第八次scrum meeting