當前位置:成語大全網 - 新華字典 - C# 中如何遍歷隊列元素

C# 中如何遍歷隊列元素

C#使用foreach語句遍歷隊列(Queue)的方法

using System;

using System.Collections;

public class QueuesW3

{

static void Main(string[] args)

{

Queue a = new Queue(10);

int x = 0;

a.Enqueue(x);

x++;

a.Enqueue(x);

foreach (int y in a)

{

Console.WriteLine(y);

}

a.Dequeue();

a.Clear();

}

}