6.索引器   字符串作为索引号    

public class Demo    

{        

        private Hashtable name = new Hashtable();          

        public string this[string index]        

        {            

               set            

              {                

                    name.Add(index, value);            

              }            

              get            

             {                

                     return name[index].ToString();            

             }       

       }

    }

   

public class Test    

{        

        public static void Main(string[] args)        

        {            

               Demo dd = new Demo();            

               dd["A"] = "SB";            

               dd["B"] = "EB";

               Console.WriteLine(dd["A"]);            

               Console.WriteLine(dd["B"]);          

             //Console.WriteLine(dd["C"]);           

               Console.ReadKey();        

        }    

}

相关文章:

  • 2022-12-23
  • 2022-01-21
  • 2021-05-28
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案