索引器的格式为 类型 this[类型 参数]{get;set;} 其中类型参数的类型可以多变,也可以有多个参数 class Program { static void Main(string[] args) { Test test = new Test(); Console.Write(test[1,1]); Console.ReadKey(); } } public class Test { private string[] names = new string[] { "xutao","bubu","weima","chris","alabama"}; private string[,] array = {{"1","2"},{"3","4"}}; public string this[int index] { get{ return names[index]; } set { if (index >= names.Length) throw new Exception(); names[index] = value; } } public string this[string indexStr] { get { return names[findIndex(indexStr)]; } } public string this[int first, int second] { get { return array[first, second]; } } private int findIndex(string str) { for (int i = 0; i < names.Length; i++) { if (names[i] == str) return i; } throw new Exception(); } }