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"]);