Push a stack onto another stack
问题 In C#, is there a way to push one Stack onto another Stack without iterating through the stack elements? If not, is there a better data structure I should be using? In Java you can do: stack1.addAll(stack2) I was hoping to find the C# analogue... 回答1: 0. Safe Solution - Extension Method public static class Util { public static void AddAll<T>(this Stack<T> stack1, Stack<T> stack2) { T[] arr = new T[stack2.Count]; stack2.CopyTo(arr, 0); for (int i = arr.Length - 1; i >= 0; i--) { stack1.Push