Mid Collections

How would you iterate through the elements of a Queue<T>?

Use a foreach loop. Iteration does not modify the queue.

Example:

foreach (var order in orders)

Console.WriteLine(order);

You can also use .ToArray() if needed:

string[] items = orders.ToArray();

More from C# Programming Tutorial

All questions for this course