Information Technology Reference
In-Depth Information
Indexer Overloading
A class can have more than one indexer, as long as the parameter lists are different. It is not suf-
ficient for the indexer type to be different. This is called indexer overloading , because all the
indexers have the same “name”—the this access reference.
For example, the following class has three indexers: two of type string , and one of type
int . Of the two indexers of type string , one has a single int parameter and the other has
two int parameters.
class MyClass
{
public string this [ int index ]
{
get { ... }
set { ... }
}
public string this [ int index1, int index2 ]
{
get { ... }
set { ... }
}
public int this [ float index1 ]
{
get { ... }
set { ... }
}
...
}
Note Remember that what is important is that the parameter lists be different in each of the overloaded
indexers of the class.
Search WWH ::




Custom Search