是遍历一个队列< T>保证在队列顺序? [英] Is iterating over a Queue<T> guaranteed to be in queue order?

查看:174
本文介绍了是遍历一个队列< T>保证在队列顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

难道这保证始终打印 123

Queue<string> theQueue = new Queue<string>();
theQueue.Enqueue("1");
theQueue.Enqueue("2");
theQueue.Enqueue("3");
foreach(var str in theQueue)
{
    Console.Write(str);
}
Console.WriteLine();

编辑: 我完全同意,队列,在任何其他命令列举的将是明显的不正确。这就是为什么我问的问题。但是,抽象数据类型队列不仅使关于它的排队离队操作。

I totally agree that a queue that enumerated in any other order would be obviously incorrect. That's why I asked the question. However, the abstract data type queue only makes guarantees about its enqueue and dequeue operations.

我在寻找引用文件,保证这种排序在.net BCL的答案。

I'm looking for an answer that references documentation that guarantees this ordering in the .NET BCL.

推荐答案

是的。它是。队列是一个先入先出的收集和为了将枚举。

Yes. It is. A queue is a first-in, first-out collection and will be enumerated in order.

这篇关于是遍历一个队列&LT; T&GT;保证在队列顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆