using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace IndexTest { class Clerk { private string name; public string Name { get { return name; } set { name = value; } } private char gender; public char Gender { get { return gender; } set { if (value != '男' && value != '女') gender = '男'; else gender = value; } } private int[] myint = new int[10]; //定义索引器 public int this[int index] { get { return myint[index]; } set { myint[index] = value; } } //虚索引器 //public virtual int this[int index] //{ // get { return myint[index]; } // set { myint[index] = value; } //} 外部索引器 //public extern int this[int index] //{ // get; // set; //} } //抽象索引器 abstract class ClerkOther { public abstract int this[int index] { set; get; } } class Program { static void Main(string[] args) { } } }