Indexer features
1. get accessors return values. Set accessors allocation value.
2. this keyword is used to define the indexer.
3. The value keyword is used to define the value allocated by the set indexer.
4. The indexer does not need to perform an index based on the integer. It is up to you to decide how to define a specific search mechanism.
5. The indexer can be overloaded.
6. The indexer can have multiple parameters, for example, when accessing a two-dimensional array.
7. The indexer allows objects to be indexed in a way similar to an array.
Sample Code
Copy codeThe Code is as follows:
Class SampleCollection <T>
{
Private T [] arr = new T [100];
Public T this [int I]
{
Get
{
Return arr [I];
}
Set
{
Arr [I] = value;
}
}
}
Class Program
{
Static void Main (string [] args)
{
SampleCollection <string> stringCollection = new SampleCollection <string> ();
StringCollection [0] = "Hello, World ";
System. Console. WriteLine (stringCollection [0]);
}
}