stack示例_C.示例中的Stack.Clone()方法
生活随笔
收集整理的這篇文章主要介紹了
stack示例_C.示例中的Stack.Clone()方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
stack示例
C#Stack.Clone()方法 (C# Stack.Clone() method)
Stack.Clone() method is used to create a shallow copy of the stack.
Stack.Clone()方法用于創建堆棧的淺表副本。
Syntax:
句法:
Object Stack.Clone();Parameters: None
參數:無
Return value: Object – a shallow copy of the stack.
返回值: Object –堆棧的淺表副本。
Example:
例:
declare and initialize a stack:Stack stk = new Stack();insertting elements:stk.Push(100);stk.Push(200);stk.Push(300);stk.Push(400);stk.Push(500);creating clone/copy of the stack:Stack stk1 = (Stack)stk.Clone();Output:stk: 500 400 300 200 100stk1: 500 400 300 200 100C#示例使用Stack.Clone()方法創建堆棧的淺表副本 (C# example to create a shallow copy of the stack using Stack.Clone() 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();//insertting elementsstk.Push(100);stk.Push(200);stk.Push(300);stk.Push(400);stk.Push(500);//printing stack elementsConsole.WriteLine("Stack (stk) elements are...");printStack(stk);//creating clone/copy of the stackStack stk1 = (Stack)stk.Clone();//printing stack elementsConsole.WriteLine("Stack (stk1) elements are...");printStack(stk1);//hit ENTER to exitConsole.ReadLine();}} }Output
輸出量
Stack (stk) elements are... 500 400 300 200 100 Stack (stk1) elements are... 500 400 300 200 100Reference: Stack.Clone Method
參考: Stack.Clone方法
翻譯自: https://www.includehelp.com/dot-net/stack-clone-method-with-example-in-c-sharp.aspx
stack示例
總結
以上是生活随笔為你收集整理的stack示例_C.示例中的Stack.Clone()方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转载] python中的数组类型及特点
- 下一篇: Java类class getClasse