dictionary List

class Program
    {
        static void Main(string[] args)
        {
            Hashtable hs=new Hashtable();
            List<Game> collection=new List<Game>(120);
            Game[] fs=
                {
                    new Game(1,"100","alisdun"), 
                    new Game(2,"200","blisdun"), 
                    new Game(3,"300","clisdun"), 
                    new Game(4,"400","dlisdun"), 
                    new Game(5,"500","elisdun"), 
                    new Game(6,"600","flisdun"), 
                    new Game(7,"700","glisdun"), 
                    new Game(8,"800","hlisdun"), 
                    new Game(9,"900","ilisdun"), 
                    new Game(10,"1100","jlisdun"), 
                    new Game(11,"1200","klisdun") 
                };
            foreach (var game in fs)
            {
                hs.Add(game.Gid,game);

                collection.Add(game);
            }

            Console.WriteLine("打印原始Hashtable中。。。。。");
            foreach (DictionaryEntry game in hs)
            {
                Console.WriteLine(((Game)game.Value).Gid + " ; " + ((Game)game.Value).Record + " ; " + ((Game)game.Value).Alliance);
            }
            Console.WriteLine();

            Console.WriteLine("移除hashtable键11,修改键10的值。。。。。");

            hs.Remove(11);
            ((Game)hs[10]).Record = "denny";
           ((Game)hs[10]).Alliance= "ahah";;

            Console.WriteLine("打印collection中。。。。。");
            foreach (var game in collection)
            {
                Console.WriteLine(game.Gid+" ; "+game.Record+" ; "+game.Alliance);
            }

            Console.WriteLine();
            Console.WriteLine("打印修改后Hashtable中。。。。。");
            foreach (DictionaryEntry game in hs)
            {
                Console.WriteLine(((Game)game.Value).Gid + " ; " + ((Game)game.Value).Record+" ; "+((Game)game.Value).Alliance);
            }
            Console.WriteLine();

            Console.WriteLine("修改collection。。。。。");
            collection[0].Record = "duck";
            Console.WriteLine("打印修改collection后Hashtable中。。。。。");
            foreach (DictionaryEntry game in hs)
            {
                Console.WriteLine(((Game)game.Value).Gid + " ; " + ((Game)game.Value).Record + " ; " + ((Game)game.Value).Alliance);
            }
            Console.ReadKey();
        }
    }

    class Game
    {
        public int Gid;
        public string Record;
        public string Alliance;
        public Game(int gid,string record,string alliance)
        {
            Gid = gid;
            Record = record;
            Alliance = alliance;
        }
    }

 

posted @ 2014-03-26 09:23  dennys  阅读(213)  评论(0编辑  收藏  举报