📅  最后修改于: 2020-10-31 10:22:15             🧑  作者: Mango
C#堆栈
让我们看一个通用堆栈的例子
using System;
using System.Collections.Generic;
public class StackExample
{
public static void Main(string[] args)
{
Stack names = new Stack();
names.Push("Sonoo");
names.Push("Peter");
names.Push("James");
names.Push("Ratan");
names.Push("Irfan");
foreach (string name in names)
{
Console.WriteLine(name);
}
Console.WriteLine("Peek element: "+names.Peek());
Console.WriteLine("Pop: "+ names.Pop());
Console.WriteLine("After Pop, Peek element: " + names.Peek());
}
}
输出:
Sonoo
Peter
James
Ratan
Irfan
Peek element: Irfan
Pop: Irfan
After Pop, Peek element: Ratan