Beispiel #1
0
        public UserEnumerator2 GetUserEnumerator2()
        {
            UserEnumerator2 enume = new UserEnumerator2(list);

            return(enume);
        }
Beispiel #2
0
        static void GenericListEnumeratorRun()
        {
            List <User> cuslist = new List <User>();

            User cus1 = new User();

            cus1.Name = "Fatima";
            cus1.Age  = 57;
            cuslist.Add(cus1);

            User cus2 = new User();

            cus2.Name = "Evangeline";
            cus2.Age  = 52;
            cuslist.Add(cus2);

            User cus3 = new User();

            cus3.Name = "Damien";
            cus3.Age  = 49;
            cuslist.Add(cus3);

            User cus4 = new User();

            cus4.Name = "Cameroon";
            cus4.Age  = 55;
            cuslist.Add(cus4);

            User cus5 = new User();

            cus5.Name = "Babu";
            cus5.Age  = 24;
            cuslist.Add(cus5);

            UserCollection cuscoll = new UserCollection(cuslist);

            Console.WriteLine("___Older users with enumerator___");

            UserEnumerator2 sen = new UserEnumerator2(cuslist);

            foreach (User cus in cuscoll.GetUserEnumerator2())
            {
                Console.WriteLine(cus.Name + "   " + cus.Age);
            }
            Console.WriteLine("");
            Console.WriteLine("___Younger users with enumerator___");
            foreach (User cus in cuscoll.GetUserEnumerator1())
            {
                Console.WriteLine(cus.Name + "   " + cus.Age);
            }
            Console.WriteLine("");

            Console.WriteLine("___Older User w/ enumarator______");
            foreach (User cus in cuslist)
            {
                if (cus.Age > 50)
                {
                    Console.WriteLine(cus.Name + "   " + cus.Age);
                }
            }
            Console.WriteLine("");
            Console.WriteLine("___Younger User w/ enumarator___");
            foreach (User cus in cuslist)
            {
                if (cus.Age < 50)
                {
                    Console.WriteLine(cus.Name + "   " + cus.Age);
                }
            }

            System.Console.WriteLine("\nDone");
            Console.Read();
        }