The way I look at indexers is that (rightly or wrongly!), accessing something by index should be more efficient than accessing it any other way, because in some way, shape or form, the class whose indexer I'm using stores some form of index that allows it to quickly lookup values when accessed that way.
The classical example is an array, when you access element n of an array by using the code myarray[3], the compiler/interpreter knows how big (memory-wise) elements of the array are and can treat it as an offset from the start of the array. You could also "for(int i = 0; i<myarray.length; i++) { if (i = 3) then { .. do stuff } }" (not that you'd ever want to!), which would be less efficient. It also shows how an array is a bad example.
Say you had a collection class that stores, umm, DVDs, so:
public class DVDCollection
{
private static Dictionary<string, DVD> store = new Dictionary<string, DVD>();
private static Dictionary<ProductId, string> dvdsByProductId = new Dictionary<string, string>();
public DVDCollection()
{
// ... gets DVD data from somewhere and stores it *by* TITLE in "store"
// ... stores a lookup set of DVD ProductId's and names in "dvdsByProductid"
}
// Get the DVD concerned, using an index, by product Id
public DVD this[ProductId index]
{
string title = dvdsByProductId[index];
return store[title];
}
}
Just my 2p, but, like I said,.. I've always considered an "indexer" as being an expedient way of getting data out of something.