예제 #1
0
        // 何かデータの集まり
        IAggregate <int> CreateAggregate()
        {
            var aggregate = new ConcreteAggregate <int>(10);

            aggregate.Add(1);
            aggregate.Add(2);
            aggregate.Add(3);
            return(aggregate);
        }
예제 #2
0
 private void Form1_Load(object sender, EventArgs e)
 {
     agg.Add("Alliance");
     agg.Add("Danish Bears");
     agg.Add("Elements Pro");
     agg.Add("mousesports");
     agg.Add("Natus Vincere");
     agg.Add("OG");
     agg.Add("PENTA Sports");
     agg.Add("Team Liquid");
     agg.Add("Team Secret");
 }
예제 #3
0
        private static void IteratorTest()
        {
            ConcreteAggregate <string> aggr = new ConcreteAggregate <string>();

            aggr.Add("One");
            aggr.Add("Two");
            aggr.Add("Three");
            aggr.Add("Four");
            aggr.Add("Five");

            IIterator <string> iterator = aggr.CreateIterator();

            do
            {
                Console.WriteLine(iterator.Current);
            }while (iterator.MoveNext());
        }
예제 #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            IAggregate aggregate = new ConcreteAggregate();

            aggregate.Add("1");
            aggregate.Add("2");
            aggregate.Add("3");

            //获取迭代器,用于访问器内部的集合
            IIterator iterator = aggregate.GetIterator();

            while (iterator.HasNext())
            {
                Console.WriteLine(iterator.Next());
            }

            Console.ReadLine();
        }
예제 #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Custom Iterator pattern implementation");
            ConcreteAggregate <int> collection = new ConcreteAggregate <int>();

            collection.Add(1);
            collection.Add(2);
            collection.Add(3);
            collection.Add(4);
            collection.Add(5);

            IIterator <int> iterator = collection.CreateIterator();

            while (iterator.Next())
            {
                int item = iterator.Current;
                Console.WriteLine(item);
            }

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

            //Itertator pattern implementation in .NET
            Console.WriteLine(".Net Iterator pattern implementation");
            IEnumerable <int> elements = new List <int>()
            {
                1, 2, 3, 4, 5
            };

            IEnumerator <int> enumerator = elements.GetEnumerator();

            while (enumerator.MoveNext())
            {
                int currentElement = enumerator.Current;
                Console.WriteLine(currentElement);
            }
        }
예제 #6
0
        public Form1()
        {
            InitializeComponent();

            // Create an aggregate to be turned in to an iterator.
            aggregate = new ConcreteAggregate();

            // Adding elements to the aggregate, this would normally not be
            // done this way. For the sake of the demo it will work. I made
            // the Person object just to learn about objects in C#, specifically
            // the ToString() method.
            aggregate.Add(new Person("Joe", 24));
            aggregate.Add(new Person("Alicia", 24));
            aggregate.Add(new Person("Roger", 58));
            aggregate.Add(new Person("Beth", 51));
            aggregate.Add(new Person("Emily", 22));
            aggregate.Add(new Person("Dave", 103));

            // Turn the aggregate into the iterator.
            iterator = aggregate.CreateIterator();

            FillListBox();
            SetLblTxt();
        }