c#_索引器

//以字符串为下标的索引器
    public class IDXer2
    {
        private Hashtable name = new Hashtable();
        //以字符串为下标的索引器
        public string this[string index]
        {
            get
            {
                return name[index].ToString();
            }
            set
            {
                name.Add(index, value);
            }
        }
    }
    public class Program
    {
        static void Main(string[] args)
        {
            //以字符串为下标的索引器
            IDXer2 indexer2 = new IDXer2();
            indexer2["A01"] = "张三";
            indexer2["A02"] = "李四";
            Console.WriteLine(indexer2["A01"]);
            Console.WriteLine(indexer2["A02"]);
            Console.ReadKey();
        }  }
 
 
 
 
 
//以字符串为下标的索引器
    public class IDXer2
    {
        private Hashtable name = new Hashtable();
        //以字符串为下标的索引器
        public string this[string index]
        {
            get
            {
                return name[index].ToString();
            }
            set
            {
                name.Add(index, value);
            }
        }
    }
    public class Program
    {
        static void Main(string[] args)
        {
            //以字符串为下标的索引器
            IDXer2 indexer2 = new IDXer2();
            indexer2["A01"] = "张三";
            indexer2["A02"] = "李四";
            Console.WriteLine(indexer2["A01"]);
            Console.WriteLine(indexer2["A02"]);
            Console.ReadKey();
        }  }
 
 
 
 
 
 
 
https://www.cnblogs.com/lxblog/p/3940261.html

c#_索引器

上一篇:【转】如何在 Windows 10、Windows 8 启动时自动装载 VHD


下一篇:C# 中Partial的用法