I\'ve seen lot of examples for c# Indexers, but in what way will it help me in real life situations.
I know the C# guru wouldn\'t have added this if it wasn\'t a ser
Let's say you have a collection of objects that you want to be able to index by something other than the order in which it was placed in a collection. In the example below, you can see how you could use the 'Location' property of some object and using the indexer, return all objects in the collection that match you location, or in the second example, all objects that contain a certain Count() of objects.
class MyCollection {
public IEnumerable this[string indexer] {
get{ return this.Where(p => p.Location == indexer); }
}
public IEnumerable this[int size] {
get{ return this.Where(p => p.Count() == size);}
}
}