예제 #1
0
        public object Clone() // method for Clone
        {
            Dictionary <Hero, List <Item> > clonDic = new Dictionary <Hero, List <Item> > ();

            foreach (KeyValuePair <Hero, List <Item> > f in colHero)
            {
                List <Item> cloneList = new List <Item>();
                foreach (Item f2 in f.Value)
                {
                    cloneList.Add(new Item(f2.Name, f2.Intelligence, f2.Agility, f2.Strength));
                }
                clonDic.Add(new Hero(f.Key.Name, f.Key.Intelligence, f.Key.Agility, f.Key.Strength, "CLONE"), cloneList);
            }
            CollectionHero clonCollection = new CollectionHero(clonDic);

            return(clonCollection);
        }
예제 #2
0
        static void Main(string[] args)
        {
            CollectionHero colHer = new CollectionHero();                                                        // first collection

            Console.WriteLine(new string('-', 20) + " First Show Collection of HEROES " + new string('-', 20));  // for view in console

            Console.WriteLine(colHer.ToString());                                                                // show first collection

            CollectionHero cloneColHeroes = (CollectionHero)colHer.Clone();                                      // clone collection

            Console.WriteLine(new string('-', 20) + " Show Clone Collection of HEROES " + new string('-', 20));  // for view in console

            Console.WriteLine(cloneColHeroes.ToString());                                                        // clone collection

            Console.WriteLine(new string('-', 20) + " Second Show Collection of HEROES " + new string('-', 20)); // for view in console

            Console.WriteLine(colHer.ToString());                                                                // show first collection

            Console.ReadKey();                                                                                   //stop prog
        }