using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace stack_test
{
    class Program
    {
        static void Main()
        {
            Stack sk1 = new Stack();
            Stack sk2 = new Stack();
            foreach (int i in new int[4] { 1, 2, 3, 4 })
            {
                sk1.Push(i);     //入栈
                sk2.Push(i);
            }
            foreach (int i in sk1)
            {
                Console.WriteLine(i);      //遍历
            }
            sk1.Pop();       //出栈
            Console.WriteLine("Pop");
            foreach (int i in sk1)
            {
                Console.WriteLine(i);
            }
            sk2.Peek();     //弹出最后一项不删除
            Console.WriteLine("Peek");
            foreach (int i in sk2)
            {
                Console.WriteLine(i);
            }
        }
    }
}


本文转载:CSDN博客