Indexer is a special syntax for overloading [] operator for a class. After defining an indexer, array syntaxes can be used for the class objects.
Indexer is usually used to traverse arrays. We can transfer this sort of functionality to our classes.
When creating a class of lets say Person
public class Person { private string name;
// create fields to hide the functionality Public string Name { get{return name;} set{name = value;} } // if we use this class the only one person name at a time will be saved at a time.
In order to keep a list of names we use an indexer which is used by the System.Collections namespace iEnumberable; Icollection; IList; IDictionary
public class Persons :CollectionBase { public Person this[int personIndex] // indexer { get{return (Person)List[personIndex];} set{List[personIndex]=value;} } } Here we are using the IList.List property in the ArrayList of the CollectionBase
Of Course to add members to the list we must also add functionality by way of methods that the List.Add() and List.Remove() portions of the class
Let me continue the Add functionality for you and I am sure that you can figure out the rest.
Public void Add(Person newPerson) { List.Add(newPerson); // adds the person to the list that will be accessed by the indexer }