"Daniel Miller" wrote:
What is the difference between indexers and indexed properties
(http://msdn.microsoft.com/library/de...tutorial.asp)?
I don't see what the problem is with using plain indexers is. Let's just
say I'm confused. :P
No problem, but consider that Document object example. Without the utility
classes how would you provide the ability to get the n'th word and m'th
character from the document.
1. Don't use indexers, just provide Word(int index) and Character(int index)
methods that do the same thing. This works just fine but at the expense of
losing the standard indexing syntax.
2. Use an indexer for one or the other, whichever is deemed more useful.
This has the disadvantage of making the indexing by words syntactically
different from indexing by characters.
3. Define an enumeration, say enum IndexType { Word, Char }, and make your
document indexer take two parameters, an IndexType and the index. E.g. char
nthChar = doc[Document.IndexT ype.Char, n]; I think the disadvantages of this
are obvious, although it would certainly work.
-- Tom