2026-04-13 15:40:15 +08:00
|
|
|
概念:
|
|
|
|
|
让对象像数组一样可以通过下标访问,方便程序编写
|
|
|
|
|
|
|
|
|
|
通常用法:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
语法:
|
|
|
|
|
```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();
|
|
|
|
|
```
|
|
|
|
|
注意:
|
|
|
|
|
|
2026-06-18 20:01:30 +08:00
|
|
|
#封装
|
|
|
|
|
#核心
|