Example #1
0
 public void Send(IIterator iterator, string message)
 {
     while (iterator.HasMore())
     {
         _profile = iterator.GetNext();
         SendMail(_profile.GetEmail, "Hello World");
     }
 }
Example #2
0
        private static void IteratorTest()
        {
            //create tree
            var tree = new List <TreeItem>();
            var d    = new TreeItem("D");
            var e    = new TreeItem("E");
            var f    = new TreeItem("F");
            var c    = new TreeItem("C", f);
            var b    = new TreeItem("B", c, d);
            var a    = new TreeItem("A", b, e);

            b.Parent = a;
            c.Parent = b;
            f.Parent = c;
            d.Parent = b;
            e.Parent = a;

            tree.Add(a);
            tree.Add(b);
            tree.Add(c);
            tree.Add(d);
            tree.Add(e);
            tree.Add(f);

            /*
             *               1- A
             *                 / \
             *                /   \
             *            2- B     E -6
             *              / \
             *             /   \
             *         3- C     D -5
             *           /
             *          /
             *      4- F
             */

            //create collection
            ITreeCollection treeCollection = new Tree(tree);

            //create iterator
            IIterator <TreeItem> iterator = treeCollection.GetDepthFirstIterator();

            while (iterator.HasMore())
            {
                var item = iterator.Next();
                Console.WriteLine(item.Name);
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            ArrayCollection arrayCollection = new ArrayCollection(5);

            for (int i = 0; i < arrayCollection.Length(); i++)
            {
                arrayCollection[i] = new Item($"Item {i}");
            }

            IIterator arrayIterator = arrayCollection.GetIterator();

            Console.WriteLine("Array collection iteration:");

            while (arrayIterator.HasMore())
            {
                Console.WriteLine(arrayIterator.GetNext().Name);
            }

            Console.WriteLine();

            DictionaryCollection dictionaryCollection = new DictionaryCollection();

            for (int i = 0; i < 10; i++)
            {
                dictionaryCollection[$"Key {i}"] = new Item($"Item {i}");
            }

            IIterator dictionaryIterator = dictionaryCollection.GetIterator();

            Console.WriteLine("Dictionary collection iteration:");

            while (dictionaryIterator.HasMore())
            {
                Console.WriteLine(dictionaryIterator.GetNext().Name);
            }
        }