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

Why can't I make a static indexer?

P: n/a
Basically, i've got a class called RegularExpressions which contains a
private Hashtable of RegExps used in my apps.

I obviously don't want to give full public access to the Hashtable, so I'd
like to define a static indexer so that the following syntax is possible

e.g.
ns.RegularExpressions[RegEx.PostCode]

I've got a static method that does this, but i want to know if it's possible
to create a static indexer?

tia
sam martin
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Sam,

No, it is not (if it was, they might have chosen a better word to
represent it).

I believe that the intent behind an indexer is to represent ways of
accessing items in collections (think of collections as a generic term
here). Your RegularExpressions class doesn't appear to be strictly a
collection (then again, that's hard to say). Rather, create a strongly
typed collection which returns your expressions, and then expose that
through a static property. Your syntax would be:

ns.RegularExpressions.Expressions[RegEx.PostCode]

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sam Martin" <sa*********@yahoo.co.uk> wrote in message
news:uF**************@TK2MSFTNGP09.phx.gbl...
Basically, i've got a class called RegularExpressions which contains a
private Hashtable of RegExps used in my apps.

I obviously don't want to give full public access to the Hashtable, so I'd
like to define a static indexer so that the following syntax is possible

e.g.
ns.RegularExpressions[RegEx.PostCode]

I've got a static method that does this, but i want to know if it's
possible to create a static indexer?

tia
sam martin

Nov 16 '05 #2

P: n/a
I wrote a blog entry a while back precisely about this issue. You can read it here:

http://www.dotnetconsult.co.uk/weblo...b-1b6539303e6b

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog/
http://www.dotnetconsult.co.uk

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<uF**************@TK2MSFTNGP09.phx.gbl>

Basically, i've got a class called RegularExpressions which contains a
private Hashtable of RegExps used in my apps.

I obviously don't want to give full public access to the Hashtable, so I'd
like to define a static indexer so that the following syntax is possible

e.g.
ns.RegularExpressions[RegEx.PostCode]

I've got a static method that does this, but i want to know if it's possible
to create a static indexer?

tia
sam martin

Nov 16 '05 #3

P: n/a
thanks

"Sam Martin" <sa*********@yahoo.co.uk> wrote in message
news:uF**************@TK2MSFTNGP09.phx.gbl...
Basically, i've got a class called RegularExpressions which contains a
private Hashtable of RegExps used in my apps.

I obviously don't want to give full public access to the Hashtable, so I'd
like to define a static indexer so that the following syntax is possible

e.g.
ns.RegularExpressions[RegEx.PostCode]

I've got a static method that does this, but i want to know if it's
possible to create a static indexer?

tia
sam martin

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.