C# 自定义索引

class Person
    {
        private static Dictionary<string, string> dict;
        static Person()
        {
            dict = new Dictionary<string, string>();
            dict.Add("a", "tom");
            dict.Add("b", "jack");
            dict.Add("c", "zhangsan");
        }
        public  string this[string id]
        {
            get
            {
                return dict[id];
            }
            set
            {
                dict[id] = value;
            }
        }
    }
Console.WriteLine(new Person()["a"]);
原文地址:https://www.cnblogs.com/trykle/p/15175339.html