By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,903 Members | 1,677 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,903 IT Pros & Developers. It's quick & easy.

Indexed properties?

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"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.IndexType.Char, n]; I think the disadvantages of this
are obvious, although it would certainly work.

-- Tom

Nov 17 '05 #2

P: n/a
Thanks!

"Thomas W. Brown" wrote:
"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.IndexType.Char, n]; I think the disadvantages of this
are obvious, although it would certainly work.

-- Tom

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.