枚举类型

 namespace ConsoleApplication1
{
    public class Stack : IEnumerable
    {
        public int[] items = { 0, 1, 2, 3 };
        public IEnumerator GetEnumerator()
        {
            for (int i = 0; i < items.Length; i++)
                yield return items[i];
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Stack stack=new Stack();
            IEnumerator i=stack.GetEnumerator();
            while (i.MoveNext())
            {
                Console.Write(i.Current);
            }
            Console.Read();
        }
    }
}

posted on 2010-08-05 22:15  java课程设计  阅读(176)  评论(0编辑  收藏  举报

导航