日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

stack示例_C.示例中的Stack.CopyTo()方法

發布時間:2025/3/11 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 stack示例_C.示例中的Stack.CopyTo()方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

stack示例

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

Stack.CopyTo() method is used to copy the stack elements/objects to an existing array from the given index.

Stack.CopyTo()方法用于將堆棧元素/對象從給定索引復制到現有數組。

Syntax:

句法:

void Stack.CopyTo(Array, Int32);

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

參數: Array – 必須在其中復制堆棧元素/對象的目標array_name , Int32 –是目標array_name中從中復制堆棧元素/對象的索引。

Return value: void – it returns nothing.

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

Example:

例:

declare and initialize a stack:Stack stk = new Stack();an array declaration for 20 elements:int[] arr = new int[20];insertting elements:stk.Push(100);stk.Push(200);stk.Push(300);stk.Push(400);stk.Push(500);using CopyTo(), copying stack elements to the array:stk.CopyTo(arr, 3); //will copy from 3rd index in arrayOutput:arr: 0 0 0 500 400 300 200 100 0 0 0 0 0 0 0 0 0 0 0 0

使用Stack.CopyTo()方法將堆棧元素/對象復制到數組的C#示例 (C# example to copy stack elements/objects to an array using Stack.CopyTo() method)

using System; using System.Text; using System.Collections;namespace Test {class Program{//function to print stack elementsstatic void printStack(Stack s){foreach (Object obj in s){Console.Write(obj + " ");}Console.WriteLine();}static void Main(string[] args){//declare and initialize a stackStack stk = new Stack();//an array declaration for 20 elementsint[] arr = new int[20];//insertting elementsstk.Push(100);stk.Push(200);stk.Push(300);stk.Push(400);stk.Push(500);//printing stack elementsConsole.WriteLine("Stack elements are...");printStack(stk);//printing array Console.WriteLine("Array elements before CopyTo()...");foreach (int item in arr){Console.Write(item + " ");}Console.WriteLine();//using CopyTo(), copying stack elements to the arraystk.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

輸出量

Stack elements are... 500 400 300 200 100 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 500 400 300 200 100 0 0 0 0 0 0 0 0 0 0 0 0

Reference: Stack.CopyTo(Array, Int32) Method

參考: Stack.CopyTo(Array,Int32)方法

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

stack示例

總結

以上是生活随笔為你收集整理的stack示例_C.示例中的Stack.CopyTo()方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。