Mid Collections

How do you check whether a Stack<T> is empty?

Use the Count property.

if (stack.Count == 0)

Console.WriteLine("Stack is empty");

Unlike some languages, C# stacks do not provide an IsEmpty property.

Follow:

More from C# Programming Tutorial

All questions for this course