Mid
From PDF
Collections
C# Collections
How would you iterate through a Stack<T>?
Short answer: Use a foreach loop, which iterates from top to bottom (LIFO order). Example: foreach (var item in stack)
Example code
{ Console.WriteLine(item); } This does not modify the stack β it's read-only iteration. π C# HashSet<T> β Interview Questions & Answers
Real-world example (ShopNest)
ShopNest uses a Queue<Order> for βorders waiting for payment confirmation,β and a Stack<Uri> for back-navigation in the admin UI.
Say this in the interview
- Define β one clear sentence (the short answer above).
- Example β relate it to a project like ShopNest or your real work.
- Trade-off β when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png