c#queue
C#Queue.Clone()方法 (C# Queue.Clone() method)
Queue.Clone() method is used to create a shallow copy of a Queue, in other words we can say it can be used to create a clone to a Queue.
Queue.Clone()方法用于创建Queue的浅表副本,换句话说,可以说它可用于创建Queue的克隆。
Syntax:
句法:
Object Queue.Clone();
Parameters: None
参数:无
Return value: Object – it returns an object containing copy to the Queue.
返回值: Object –它向队列返回包含副本的对象。
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);
copying the Queue:
Queue que1 = (Queue)que.Clone();
Output:
que elements...
100 200 300 400 500
que1 elements...
100 200 300 400 500
C#示例使用Queue.Clone()方法创建到Queue的副本 (C# example to create a copy to the Queue using Queue.Clone() 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();
//insertting elements
que.Enqueue(100);
que.Enqueue(200);
que.Enqueue(300);
que.Enqueue(400);
que.Enqueue(500);
//copying the Queue
Queue que1 = (Queue)que.Clone();
//printing Queues
Console.WriteLine("que elements...");
printQueue(que);
Console.WriteLine("que1 elements...");
printQueue(que);
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
输出量
que elements...
100 200 300 400 500
que1 elements...
100 200 300 400 500
Reference: Queue.Clone Method
参考: Queue.Clone方法
翻译自: https://www.includehelp.com/dot-net/queue-clone-method-with-example-in-c-sharp.aspx
c#queue