索引器
来源:互联网 发布:2kol球员数据更新2017 编辑:程序博客网 时间:2024/04/30 11:11
就是索引,比如一个数组a[10] 索引就是从0到9 Index是类的一个索引符,C#对类引进了索引符的操作,是为了有时候可以将类当作数组来用,如下所示: class Person { private string name; private string sex; private string title; public string this[int i] { get { switch(i) { case 0: return name; case 1: return sex; case 2: return title; defualt: throw new IndexOutRangeException(); } set { switch(i) { case 0: name=value; break; case 1: sex=value; break; case 2: title=value; break; default: throw new IndexOutOfException(); } } } } 定义了索引符之后,我们就可以像这样使用类了: Person person1=new Person(); person1[0]="Jack"; person1[1]="Male"; person1[2]="Programer"; for(int i=0;i<3;i++) { Console.WriteLine(person[i]); }
0 0
- 索引器
- 索引器
- 索引器
- 索引器
- 索引器
- 索引器
- 索引器
- 索引器
- 索引器
- 索引器
- 索引器
- 索引器
- 索引器
- 索引器
- 索引器
- 索引器
- 索引器
- 索引器
- Bilateral Filter
- Map与Hash
- discuz x3.1实现QQ登录
- 菜鸟Android学习31——图片预览窗口
- 文件系统相关文章地址
- 索引器
- Storm安装
- Hadoop源码分析之NameNode的启动与停止
- B+ Tree 与 B- Tree
- poj 1006 Biorhythms
- 读书笔记——Windows环境下32位汇编语言程序设计(5)模态对话框
- JSP访问Hadoop 图片存储服务
- 如何面试前端工程师:Github很重要
- OC对象的动态和静态构造区别