Initial commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
概念:
|
||||
让对象像数组一样可以通过下标访问,方便程序编写
|
||||
|
||||
通常用法:
|
||||
|
||||
|
||||
语法:
|
||||
```Csharp
|
||||
访问修饰符 返回值 this[参数类型 参数名1,参数类型 参数名2.....]
|
||||
{
|
||||
get{} ==内部写法和属性相似==
|
||||
set{}
|
||||
}
|
||||
```
|
||||
|
||||
案例:
|
||||
```Csharp
|
||||
class Person
|
||||
{
|
||||
private string name;
|
||||
priavte int age;
|
||||
private Person[] friends;
|
||||
public Person this[int index]
|
||||
{
|
||||
get{return friends[index];}
|
||||
set{friends[index] = value;}
|
||||
}
|
||||
}
|
||||
|
||||
Person p1 = new Person();
|
||||
p[0] = new Person();
|
||||
```
|
||||
注意:
|
||||
|
||||
Reference in New Issue
Block a user