console.writeline(index)
int temp = t[]
private string[] name new string[10]
构造函数
string[] name = new string[10]
int i = 0
foreach(string temp in days){
uf
}
p
public int this[string day]
{
}
console.writeline(index)
int temp = t[]
private string[] name new string[10]
构造函数
string[] name = new string[10]
int i = 0
foreach(string temp in days){
uf
}
p
public int this[string day]
{
}
索引器
定义索引器电脑方法:
public int this 【int index】
{
get{}set{}
}
使用索引器的方法:取值,赋值
运算器重载
索引器的使用在主函数中
Console.WriteLine(wk["Thur"]);
在类中 public int this[string day]
{
get
{ }
}、
索引器相对于普通函数书写跟整洁
索引器作用:
类中声明数组,通过函数来给数组赋值或者读取
索引器:
private int[] z=new int[10];
public int sy[int i]
{
get{return z[i];}set{z[i]=value;}
}
索引器的声明类似于属性,但使用this关键字和一个或多个参数来表示索引。例如,如果你的类表示一个合计,可以使用整数索引来访问集合中的元素。
在索引器的get访问器中实现获取索引处元素的逻辑,通过return返回相应的值。在set访问器中实现设置索引处元素的逻辑。
索引器可以有多个参数,以支持多维索引或其它复杂的索引方案。
C#还允许你在索引器中使用不同的数据类型作为索引,例如字符串或自定义类型。
索引关键字 this
public string this[int index]{
get{
return name [index];
}
set{
name[index] = value;
}
}