C#--事件和索引指示器

事件为类和类的实例提供了向外界发送通知的能力,而索引指示器则可以像数组那样对对象进行索引访问。

事件所声明的类型必须是一个代表类型,代表类型应预先声明。

索引指示器例子:

using System; namespace Welcome { class Program { static void Main(string[] args) { Index index = new Index(); Console.WriteLine(index[2]); index[2] = 0; for (int i = 0; i < 5; i++) { Console.WriteLine(index[i]); } Console.Read(); } } class Index { private int[] temp = {1,2,3,4,5 }; /** * 索引指示器,主要效果是封装。 */ public int this[int index] { get { return temp[index]; } set{ temp[index] = value; } } } }


结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值