Is iterating over a Queue<T> guaranteed to be in queue order?
问题 Is this guaranteed to always print 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(); Edit: 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. I'm looking for an answer that