예제 #1
0
        static void Main(string[] args)
        {
            UserCollectionWithoutIEnum withoutIEnum = new UserCollectionWithoutIEnum();//>??

            foreach (var k in withoutIEnum)
            {
                Console.WriteLine(k.ToString());
            }
            Console.WriteLine("-y----------------------------------------------------");
            UserCallectionWithYieldReturn yieldUsers = new UserCallectionWithYieldReturn();

            foreach (var yieldUser in yieldUsers)
            {
                Console.WriteLine(yieldUser.ToString());
            }
            Console.WriteLine("------------------------------------------------");
            UserCollectionWithInnerClassIEnum mycallection = new UserCollectionWithInnerClassIEnum();

            foreach (var call in mycallection)
            {
                Console.WriteLine(call.ToString());
            }
            Console.WriteLine("------------------------------------");
            UserCollectionNew userNew = new UserCollectionNew();

            foreach (var user in userNew)
            {
                Console.WriteLine(user.ToString());
            }
            Console.WriteLine("-------------------------------");
            UserCollection users      = new UserCollection();
            IEnumerable    enumerable = users as IEnumerable;

            IEnumerator enumerator = users.GetEnumerator();

            while (enumerator.MoveNext())
            {
                User user = enumerator.Current as User;
                Console.WriteLine(user.ToString());
            }
            Console.WriteLine("-----------------------------------------------------");
            foreach (var u in users)
            {
                Console.WriteLine(u.ToString());
            }
        }
 public Enumerator(UserCollectionWithInnerClassIEnum collection)
 {
     this.MyCollection = collection;
 }