csharp iterate and pop all elements in stack

Code Example - csharp iterate and pop all elements in stack

                
                        Stack<Action> stack = new Stack<Action>();
stack.Push(()=>{Console.Write("executed");});

while (stack.Count>0){
    stack.Pop().Invoke();
}