public static void Main() { try { Stack<int> stack = new Stack<int>(); stack.Push(1); stack.Push(2); stack.Push(3); stack.Push(4); stack.Push(5); int[] array = stack.ToArray(); Console.WriteLine(string.Join(", ", array)); Console.WriteLine(stack.Peek()); Console.WriteLine(stack.Pop()); Console.WriteLine(stack.Contains(0)); stack.Clear(); Console.WriteLine(stack.Peek()); } catch (ArgumentNullException aex) { Console.WriteLine(aex.TargetSite + " -> " + aex.Message); } }
public void Clear() { Stack<int> stack = new Stack<int>(); stack.Push(10); stack.Clear(); Assert.IsTrue(stack.Size() == 0); }