C#初始索引器
string[] s = new string[5];
最常见的数组,中括号[ ],通过下标访问,即通过索引访问
关于索引器
class Person { Dictionary<string, string> dic = new Dictionary<string, string>(); public string this[string index] { get { return dic[index]; } set { dic[index] = value; } } } class Program { static void Main(string[] args) { Person p = new Person(); p["1"] = "索"; p["2"] = "引"; p["3"] = "器"; Console.WriteLine(p["1"]); Console.WriteLine(p["2"]); Console.WriteLine(p["3"]); //输出内容: 索引器 Console.ReadKey(); } }