Mid Collections

How would you iterate through a Stack<T>?

Use a foreach loop, which iterates from top to bottom (LIFO order).

Example:

foreach (var item in stack)

Console.WriteLine(item);

This does not modify the stack — it's read-only iteration.

📘 C# HashSet<T> – Interview Questions

& Answers

More from C# Programming Tutorial

All questions for this course