索引器可以看做名字为this的一个属性,
通过get和set语句块设置索引器的行为。
public ValueType this[KeyType key]
{
get
{
return ...
}
set
{
//value关键字表示set的值
}
}
其中,
KeyType表示索引的类型,ValueType表示索引器返回的类型。
索引器可以看做名字为this的一个属性,
通过get和set语句块设置索引器的行为。
public ValueType this[KeyType key]
{
get
{
return ...
}
set
{
//value关键字表示set的值
}
}
其中,
KeyType表示索引的类型,ValueType表示索引器返回的类型。