• C#索引器3 重载


        7.索引器  重载    

    public class Demo    

    {        

              private Hashtable name = new Hashtable();          

              public string this[int index]        

             {            

                     get            

                     {                

                          return name[index].ToString();            

                     }            

                     set            

                     {                

                           name.Add(index, value);         

                     }        

              }

               public int this[string index]        

               {            

                      set            

                     {                

                            name.Add(value, index);            

                     }            

                     get            

                    {                

                            foreach (DictionaryEntry dd in name)                

                            {                    

                                   if (dd.Value.ToString() == index)                    

                                  {                        

                                         return Convert.ToInt32(dd.Key);                    

                                  }                

                           }                

                           return -1;            

                    }        

              }    

    }

    public class Test    

    {        

            public static void Main(string[] args)        

            {            

                   Demo dd = new Demo();            

                   dd[3] = "Lobin";            

                   dd[4] = "Jack";            

                   Console.WriteLine("3号 是 {0}",dd[3]);            

                   Console.WriteLine("4号 是 {0}",dd[4]);            

                   Console.WriteLine("Lobin的编号为: {0}", dd["Lobin"]);            

                   Console.WriteLine("Jack的编号为: {0}",dd["Jack"]);            

                   Console.ReadKey();

                   dd["Mark"] = 5;            

                   Console.WriteLine("Mark的编号为 {0}", dd["Mark"]);            

                   Console.ReadKey();        

             }    

    }

  • 相关阅读:
    hdu 4710 Balls Rearrangement()
    hdu 4707 Pet(DFS水过)
    hdu 4706 Children's Day(模拟)
    hdu 4712 Hamming Distance(随机函数暴力)
    csu 1305 Substring (后缀数组)
    csu 1306 Manor(优先队列)
    csu 1312 榜单(模拟题)
    csu 1303 Decimal (数论题)
    网络爬虫
    Python处理微信利器——itchat
  • 原文地址:https://www.cnblogs.com/gyc19920704/p/5254972.html
Copyright © 2020-2023  润新知