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元素/對象從指定的索引復制到現(xiàn)有數(shù)組。
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.
參數(shù): Array –我們必須在其中復制隊列元素/對象的目標array_name , Int32 –是目標array_name中從中復制隊列元素/對象的索引。
Return value: void – it returns nothing.
返回值: void –不返回任何內(nèi)容。
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 arrayOutput:arr: 0 0 0 100 200 300 400 500 0 0 0 0 0 0 0 0 0 0 0 0使用Queue.CopyTo()方法將隊列元素/對象復制到數(shù)組的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 elementsstatic void printQueue(Queue q){foreach (Object obj in q){Console.Write(obj + " ");}Console.WriteLine();}static void Main(string[] args){//declare and initialize a QueueQueue que = new Queue();//an array declaration for 20 elementsint[] arr = new int[20];//insertting elementsque.Enqueue(100);que.Enqueue(200);que.Enqueue(300);que.Enqueue(400);que.Enqueue(500);//printing Queue elementsConsole.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 arrayque.CopyTo(arr, 3);//printing array Console.WriteLine("Array elements after CopyTo()...");foreach (int item in arr){Console.Write(item + " ");}Console.WriteLine(); //hit ENTER to exitConsole.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 0Reference: 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
總結(jié)
以上是生活随笔為你收集整理的c#queue_带有C#示例的Queue.CopyTo()方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转载] python循环中break、
- 下一篇: scala 方法调用_Scala中的方法