Indexed properties?

  • Thread starter Thread starter Guest
  • Start date Start date
Daniel Miller said:
What is the difference between indexers and indexed properties
(http://msdn.microsoft.com/library/d...ref/html/vcwlkindexedpropertiestutorial.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.IndexType.Char, n]; I think the disadvantages of this
are obvious, although it would certainly work.

-- Tom
 
Thanks!

Thomas W. Brown said:
Daniel Miller said:
What is the difference between indexers and indexed properties
(http://msdn.microsoft.com/library/d...ref/html/vcwlkindexedpropertiestutorial.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.IndexType.Char, n]; I think the disadvantages of this
are obvious, although it would certainly work.

-- Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top