C#里的Index是什么意思?
答案:1 悬赏:60
解决时间 2021-02-11 21:32
- 提问者网友:你在我心中是最美
- 2021-02-11 05:10
C#里的Index是什么意思?
最佳答案
- 二级知识专家网友:你把微笑给了谁
- 2021-02-11 05:47
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();}}}}
定义了索引符之后,我们就可以像这样使用类了:
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();}}}}
定义了索引符之后,我们就可以像这样使用类了:
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |