Exemple #1
0
        static void Main(string[] args)
        {
            HeroList team1 = new HeroList();

            Console.WriteLine(team1.ToString());
            Console.WriteLine("----------------------------------");
            HeroList team2 = (HeroList)team1.Clone();

            Console.WriteLine(team2.ToString());
        }
        public object Clone()
        {
            List <Item> cloneList = new List <Item>();
            Dictionary <Hero, List <Item> > clonDic = new Dictionary <Hero, List <Item> >();


            foreach (KeyValuePair <Hero, List <Item> > dd in team1)
            {
                foreach (Item d in dd.Value)
                {
                    cloneList.Add(d);
                }
                clonDic.Add(dd.Key, dd.Value);
            }
            HeroList clonCollection = new HeroList(clonDic);

            return(clonCollection);
        }