Information Technology Reference
In-Depth Information
Declaring an Indexer
The syntax for declaring an indexer is shown following. Notice the following about indexers:
An indexer
does not have a name.
In place of the name is the keyword
this
.
The parameter list is between
square brackets
.
There must be at least one parameter declaration in the parameter list.
Keyword
Parameter list
↓
↓
ReturnType
this [ Type param1, ... ]
{
↑
↑
get
Square brackets
{
...
}
set
{
...
}
}
Declaring an indexer is similar to declaring a property. Figure 6-16 shows the syntactic
similarities and differences.
Figure 6-16.
Comparing an indexer declaration to a property declaration