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

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/541696.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

指针在c语言中的运用,怎么理解C语言中的指针,如何运用?

恰好我之前写了一系列介绍 C 语言的文章,介绍了什么是指针,以及为什么要使用指针,下面摘录一部分,感兴趣的话,可以点我了解更多。什么是 C语言指针?不同的数据类型的主要区别在于占用的存储空间不同。我们知…

设计模式(一)单例模式的七种写法

1. 饿汉模式 public class Singleton { private static Singleton instance new Singleton(); private Singleton (){}public static Singleton getInstance() { return instance; } } View Code这种方式在类加载时就完成了初始化,所以类加载较慢,…

scala 字符串转换数组_如何在Scala中将字节数组转换为字符串?

scala 字符串转换数组Byte Array in Scala is an array of elements of a byte type. String in Scala is a collection of the character data type. Scala中的字节数组是字节类型的元素的数组。 Scala中的String是字符数据类型的集合。 将字节数组转换为字符串 (Convert byt…

智能关机软件 c语言,智能关机软件

智能关机软件是一款免费共享关机软件。智能关机软件不但具有定时关机、自动关机的功能,而且还可以进行定时提醒信息、打开文件、打开网页、重启计算机、注销用户、锁定计算机、计算机休眠、计算机待机、关闭显示器,并且可以进行多任务计划,可…

wget: command not found

-bash: wget: command not found的两种解决方法 今天给服务器安装新LNMP环境时,wget 时提示 -bash:wget command not found,很明显没有安装wget软件包。一般linux最小化安装时,wget不会默认被安装。可以通过以下两种方法来安装:1、rpm 安装rp…

数据库数据规范化看不懂_数据库管理系统中的规范化

数据库数据规范化看不懂DBMS中的规范化 (Normalization in DBMS) Every table must have a single idea. The method by which we divide tables approximately is called normalization and the rest used for normalization is a functional dependency. For the normalizati…

c 语言开发一个四则运算器,C++实现四则运算器(无括号)

本文实例为大家分享了C实现无括号的四则运算器的具体代码,供大家参考,具体内容如下完成度更高的带括号版本可以看C实现四则运算器(带括号)对于无括号的计算器,实现起来比较容易,下面让我们一步步实现。举例首先明确需要实现怎样的…

iOS开发之解决系统数字键盘无文字时delete键无法监听的技巧

最近在做用户登录获取验证码时添加图形验证码功能,就是只有正确输入图形验证码才能收到后台发送的短信验证码。效果如下: 看起来虽然是个小功能,但是实际操作起来,会发现苹果给我们留下的坑,当然更多的是自己给自己挖的…

c ++查找字符串_C ++结构| 查找输出程序| 套装1

c 查找字符串Program 1: 程序1&#xff1a; #include <iostream>#include <math.h>using namespace std;struct st {int A NULL;int B abs(EOF EOF);} S;int main(){cout << S.A << " " << S.B;return 0;}Output: 输出&#xff1a…

二级c语言加油,二级C语言 备考指南及常见问题(2013版)

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼3、关于上机操作部分的复习最好买一本上机题库方面的教材&#xff0c;或打印、阅读南开百题之类的电子文档。配合上机模拟软件(无纸化考试软件)&#xff0c;上机练习是必须的。上机软件一般有100套题多一点&#xff0c;每套有程序填…

开放定址散列表

再散列之后散列函数要重新计算。 // kaifangliaobiao.cpp : 定义控制台应用程序的入口点。 //使用平方探测解决冲突问题时&#xff0c;散列表至少空一半时&#xff0c;总能插入一个新的元素#include "stdafx.h" #include<iostream> using namespace std;#ifnde…

合并两个链表数据结构c语言,合并两个链表.

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼#include #define N1 10#define N2 10struct list{int date ;struct list *next;};main(){struct list *p1,*p2,*p3,*p4,*head,*head1,*head2,*p;int n0;head1head2NULL;p1p2(struct list *)malloc(sizeof(struct list));p1->da…

c ++查找字符串_C ++结构| 查找输出程序| 套装2

c 查找字符串Program 1: 程序1&#xff1a; #include <iostream>using namespace std;int main(){typedef struct{int A;char* STR;} S;S ob { 10, "india" };S* ptr;ptr &ob;cout << ptr->A << " " << ptr->STR[2];…

连接fiddler后手机无法显示无网络

升级了fiddler到4.6版本&#xff0c;手机设置代理后提示无网络&#xff0c;试试以下解决方法&#xff1a; 1.fiddler升级后对应的.net framework也要升级&#xff0c;安装最新的.net framework 4.6&#xff0c;升级安装后&#xff0c;可以正确抓包啦 2.如果上述方法无效&#x…

android 人脸解锁 锁屏动画,人脸保护锁(人脸识别锁屏)

这是一款十分炫酷的锁屏工具&#xff0c;还记得电影中的特工所用的人脸识别锁吗&#xff1f;这款应用也能让你过过瘾&#xff01;人脸识别锁屏安卓版是一款用人脸做密码来打开手机屏保锁的一个APP。不仅可以作屏保锁&#xff0c;也可以单独保护某些重要程序不被偷窥,例如查看短…

dbms_排名前50位的DBMS面试问答

dbms1) What are the drawbacks of the file system which is overcome on the database management system? 1)在数据库管理系统上克服的文件系统有哪些缺点&#xff1f; Ans: Data redundancy & isolation, difficulty in accessing data, data isolation, and integri…

linux时间

CST代表中国标准时间rtc实时时钟linux主要有两种时间硬件时钟 clock系统时钟 date修改时间 date 03300924必须是两位或者 date -s 2017:03:30将系统时间同步到硬件时间 hwclock -w将硬件时间同步到系统时间 hwclock -s转载于:https://blog.51cto.com/12372297/1911608

查找Python中给定字符串的所有排列

Python itertools Module Python itertools模块 "itertools" are an inbuilt module in Python which is a collection of tools for handling iterators. It is the most useful module of Python. Here, a string is provided by the user and we have to print a…

android 图片叠加xml,Android实现图片叠加效果的两种方法

本文实例讲述了Android实现图片叠加效果的两种方法。&#xff0c;具体如下&#xff1a;效果图&#xff1a;第一种&#xff1a;第二种&#xff1a;第一种是通过canvas画出来的效果:public void first(View v) {// 防止出现Immutable bitmap passed to Canvas constructor错误Bit…

Win10系列:VC++ 定时器

计时器机制俗称"心跳"&#xff0c;表示以特定的频率持续触发特定事件和执行特定程序的机制。在开发Windows应用商店应用的过程中&#xff0c;可以使用定义在Windows::UI::Xaml命名空间中的DispatcherTimer类来创建计时器。DispatcherTimer类包含了如下的成员&#xf…