Example #1
0
        static void Main()
        {
            var collection = new UserCollection();

            foreach (var element in collection)
            {
                Console.WriteLine(element);
            }

            Console.WriteLine(new string('-', 2));

            var array = new object[collection.Count];

            collection.CopyTo(array, 0);

            foreach (int element in array)
            {
                Console.WriteLine(element);
            }

            // Delay.
            Console.ReadKey();
        }
Example #2
0
        static void Main()
        {
            var сollection = new UserCollection();

            сollection[0] = new Element(1, 2);
            сollection[1] = new Element(3, 4);
            сollection[2] = new Element(5, 6);
            сollection[3] = new Element(7, 8);

            foreach (Element element in сollection)
            {
                Console.WriteLine("{0}, {1}", element.FieldA, element.FieldB);
            }

            Console.WriteLine(new string('-', 5));

            foreach (Element element in сollection)
            {
                Console.WriteLine("{0}, {1}", element.FieldA, element.FieldB);
            }

            Console.WriteLine(new string('-', 5));

            // Так работает foreach

            IEnumerator enumerator = (сollection as IEnumerable).GetEnumerator();

            while (enumerator.MoveNext())
            {
                Element element = enumerator.Current as Element;

                Console.WriteLine("{0}, {1}", element.FieldA, element.FieldB);
            }

            // Delay.
            Console.ReadKey();
        }
Example #3
0
        static void Main()
        {
            var сollection = new UserCollection <Element>();

            сollection[0] = new Element(1, 2);
            сollection[1] = new Element(3, 4);
            сollection[2] = new Element(5, 6);
            сollection[3] = new Element(7, 8);

            foreach (Element element in сollection)
            {
                Console.WriteLine("{0}, {1}", element.FieldA, element.FieldB);
            }

            Console.WriteLine(new string('-', 5));

            foreach (Element element in сollection)
            {
                Console.WriteLine("{0}, {1}", element.FieldA, element.FieldB);
            }

            // Delay.
            Console.ReadKey();
        }
Example #4
0
 public Iterator(UserCollection <T> col)
 {
     array = col.numbers;
 }