Stack<string> statck = new Stack<string>();
Console.WriteLine("入栈操作");
statck.Push("A");
statck.Push("B");
statck.Push("C");
statck.Push("D");
foreach (var item in statck)
{
Console.WriteLine(item);
}
Console.WriteLine("出栈操作,元素是:" + statck.Pop());
foreach(var item in statck)
{
Console.WriteLine(item);
}
Console.WriteLine("栈顶元素:" + statck.Peek());
Console.WriteLine("元素个数:" + statck.Count);
foreach (var item in statck)
{
Console.WriteLine(item);
}
Console.WriteLine("是否包含元素A,true or false: " + statck.Contains("A"));
输出结果如下: