Indexer Attributes
1, get accessor return value. The set accessor assigns a value.
2, this keyword is used to define indexers.
3, the value keyword is used to define values that are assigned by the set indexer.
4. Indexers do not have to be indexed based on integer values, and you decide how to define a specific lookup mechanism.
5, indexers can be overloaded.
6. Indexers can have multiple formal parameters, such as when accessing two-dimensional arrays.
7. Indexers enable objects to be indexed in a way similar to arrays.
code example
Copy Code code 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]);
}
}