Mid
From PDF
Collections
C# 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
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png