System.Collections.Stack

using System;
using System.Collections;

namespace _08_04
{
    
public class Class_08_04
    
{
        
public static void Main(String[] args)
        
{
            Stack s 
= new Stack();

            s.Push(
"Cat");
            s.Push(
"Dog");
            s.Push(
"Bird");
            s.Push(
"Dinosaur");
            s.Push(
"Human");

            Console.WriteLine(
"堆栈中有元素 {0} 个", s.Count);

            Console.WriteLine(
"用 IEnumerator 访问所有元素:");
            IEnumerator enu 
= s.GetEnumerator(); 
            
while(enu.MoveNext())
            
{
                Console.WriteLine(
"{0}\t 堆栈中有元素 {1} 个", enu.Current.ToString(), s.Count);
            }


            Console.WriteLine();
            Console.WriteLine(
"从栈顶Pop所有元素");
            
while(s.Count > 0)
            
{
                Console.WriteLine(
"{0}\t 堆栈中有元素 {1} 个", s.Pop().ToString(), s.Count);
            }

        }

    }

}
posted @ 2007-04-27 15:08  roboth  阅读(243)  评论(0编辑  收藏  举报