public void printVegetarianMenu()
        {
            IEnumerator enumerator = allMenus.createIEnumerator();

            while (enumerator.MoveNext())
            {
                MenuComponent menuCompent = (MenuComponent)enumerator.Current;

                if (menuCompent != null && menuCompent.isVegetarian())
                {
                    menuCompent.print();
                }
            }
        }
Exemple #2
0
        //这种print的方式是内部迭代,不断地通过子类枚举遍历
        public override void print()
        {
            Console.Write("\n" + getName());
            Console.WriteLine("," + getDescription());
            Console.WriteLine("------------");
            IEnumerator enumerator = menuComponents.GetEnumerator();

            while (enumerator.MoveNext())
            {
                MenuComponent component = (MenuComponent)enumerator.Current;
                component.print();
            }

            /*
             * foreach(var item in menuComponents)
             * {
             *  ((MenuComponent)item).print();
             * }
             */
        }
 public void print()
 {
     allMenus.print();
 }