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.pswp.cn/news/541696.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541696.shtml
英文地址,請注明出處:http://en.pswp.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…