To have an indexer we use the following format:
class ClassName
{
DataType[] ArrayName = new DataType[Length];
public DataType this[int i]
{
get { return ArrayName[i]; }
}
}
For the sake of simplicity I used the format, even though we can go for a custom indexer also. According to my understanding, we are keeping a propery array that is indexed.
My question is :
- Is it a templated property?
- When and where could we achieve high degree code optimization using this indexer?
It is not about code optimization.
You could write a method in your class that can get you the item from the collection it holds.
e.g.
Indexers are in a way, “syntactic sugar”, to let users treat the instance as an array or collection.