c#中queue
C#Queue.Dequeue()方法 (C# Queue.Dequeue() method)
Queue.Dequeue() method is used to remove an object/element from the beginning of the Queue and returns that object/element.
Queue.Dequeue()方法用于从Queue的开头删除一个对象/元素,并返回该对象/元素。
Syntax:
句法:
Object Queue.Dequeue();
Parameters: None
参数:无
Return value: Object – it returns the object/element to be removed.
返回值: 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);
removing elements from Queue:
que.Dequeue();
que.Dequeue();
que.Dequeue();
Output:
400 500
C#示例使用Queue.Dequeue()方法从队列中删除对象/元素 (C# example to remove an object/element from the Queue using Queue.Dequeue() 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);
//removing elements from Queue
Console.WriteLine(que.Dequeue() + " is removed...");
Console.WriteLine(que.Dequeue() + " is removed...");
Console.WriteLine(que.Dequeue() + " is removed...");
//printing queue elements after removing elements
Console.WriteLine("Queue elements are...");
printQueue(que);
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
输出量
Queue elements are...
100 200 300 400 500
100 is removed...
200 is removed...
300 is removed...
Queue elements are...
400 500
Reference: Queue.Dequeue Method
参考: Queue.Dequeue方法
翻译自: https://www.includehelp.com/dot-net/queue-dequeue-method-with-example-in-c-sharp.aspx
c#中queue