c#中queue
C#Queue.Enqueue()方法 (C# Queue.Enqueue() method)
Queue.Enqueue() method is used to add an object/element at the end of the Queue.
Queue.Enqueue()方法用于在Queue的末尾添加一个对象/元素。
Syntax:
句法:
void Queue.Enqueue(Object);
Parameters: Object – an object/element to be added.
参数: Object-要添加的对象/元素。
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);
Output:
100 200 300 400 500
C#示例使用Queue.Enqueue()方法将对象/元素添加到队列 (C# example to add an object/element to the Queue using Queue.Enqueue() 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);
//printing queue elements
Console.WriteLine("Queue elements are...");
printQueue(que);
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
输出量
Queue elements are...
100 200 300 400 500
Reference: Queue.Enqueue(Object) Method
参考: Queue.Enqueue(Object)方法
翻译自: https://www.includehelp.com/dot-net/queue-enqueue-method-with-example-in-c-sharp.aspx
c#中queue