cody said:
what is the difference wheather i have multiple indexers or multiple
properties which returns a collection?
i see no benefit.
Okay, how would you code these situations then:
1) You have an array which you wish to index in a read-only fashion. If
you have a property which returns the array, the array can be changed
by the caller. You could copy the array, of course, but that can be
expensive. An indexer makes this very easy.
2) You have a collection of references of a certain type. If you expose
IList as a property, it leaves the caller to cast, which isn't ideal.
(You also have to create the read-only wrapper for the collection if
you want it to be read-only, and if you don't make it read-only, you
don't have control over the type-safety without a bit more work.) If
you have an indexer, you can ensure type-safety for writing, and keep
the casting code local to the class to give a better interface to the
client.
Of course, by creating your own collection classes you can return an
appropriate property - but you end up with loads of such classes, as
witnessed in the framework libraries.