using System; using System.Collections; Stack myStack = new Stack(); myStack.Push("Hello"); myStack.Push("World"); myStack.Push("!"); // Copy the elements of the stack to a new array object[] myArray = myStack.ToArray(); // Print the elements of the array foreach (object element in myArray) { Console.WriteLine(element); }In this example, we create a stack and add three elements to it. We then call the ToArray() method, which copies the elements to a new array. Finally, we iterate over the array and print each element to the console. The package library for this class is the System.Collections namespace.