📅  最后修改于: 2020-10-31 10:23:12             🧑  作者: Mango
C#队列
让我们看一个通用队列的例子
using System;
using System.Collections.Generic;
public class QueueExample
{
public static void Main(string[] args)
{
Queue names = new Queue();
names.Enqueue("Sonoo");
names.Enqueue("Peter");
names.Enqueue("James");
names.Enqueue("Ratan");
names.Enqueue("Irfan");
foreach (string name in names)
{
Console.WriteLine(name);
}
Console.WriteLine("Peek element: "+names.Peek());
Console.WriteLine("Dequeue: "+ names.Dequeue());
Console.WriteLine("After Dequeue, Peek element: " + names.Peek());
}
}
输出:
Sonoo
Peter
James
Ratan
Irfan
Peek element: Sonoo
Dequeue: Sonoo
After Dequeue, Peek element: Peter