using System; using System.Collections.Generic; using System.Text; namespace VA15.__索引器概述及声明 { class Program { public class Clerk { private string name; //内部使用 public string Name { //属性 外部引用 get { return name ;} set { name = value; } } private string gender; public string Gender { get { if (gender !="男" && gender !="女" ) gender ="男"; return gender; } set { gender = value; } } //数组索引器 private int[] myint=new int [10]; //public int this[int index] { // get { return myint[index]; } // set { myint[index] = value; } //} //虚拟索引器 virtual //public virtual int this[int index] //{ // get { return myint[index]; } // set { myint[index] = value; } //} //外部索引器 因为外部索引器不提供任何实际的实现,所有它的每个访问器声明 都由一个分号组成 //public extern int this[int index] //{ // get; // set; //} //抽象索引器 当要定义为抽象的索引 必须提供空的 get set 用来继承 } //抽象索引器 abstract class indexEaxmple { public abstract int this[int index] { get; set; } } static void Main(string[] args) { } } } |
|
来自: 时间剧毒 > 《第十八章:迭代器、分部类和索引器》