An indexer is worked as properties. Indexers allow instancesof a class or struct to be indexed just like arrays. Indexers are also calledsmart arrays in C# and can be used to treat an object as an array.
Syntax for an indexer declaration
Modifier returnType this[argument]
Some point for indexers
· Indexers concept is object act as an array.
· thiskeyword is used to define the indexers.
· A get accessor returnsa value and A set accessor assigns a value.
· Indexers cannot be static.
· Indexers can be abstract. There would be no codeinside it in such a case.
· The return type can be any valid C# types
This is thesimple example how use the indexers in c#
static void Main(stringargs)
yyya = new yyy();
a = 24;
public class yyy
public int this[int i]
Console.WriteLine("The value of array a[" + i + "]: " + value);
The value of array a: 24