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 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With