473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Syntax for a static indexer (or it is not possible) ?

Hi,
Looking for the syntax for a static indexer. For a non static 'access',
the following would do:

public class whatever
{
static Hashtable myHashtable = null;

// ----- here-----
public whatever this[string name]
{
get
{
return (whatever) myHashtable[name] ;
}
}

...
}
Clearly, that does not work prefixing with static,
static public whatever this[string name] {get{return (whatever)
myHashtable[name];} }
since 'this' cannot be used inside a static definition.

Vanderghast, Access MVP

Nov 16 '05 #1
5 3742
Michel Walsh <vanderghast@VirusAreFunnierThanSpam> wrote:
Looking for the syntax for a static indexer.


Unfortunately there's no such thing in C#. The C# team decided it
wasn't a good idea, although they've said they might revisit that
decision some time.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Hi,

Thanks for the info.

Vanderghast, Access MVP
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Michel Walsh <vanderghast@VirusAreFunnierThanSpam> wrote:
Looking for the syntax for a static indexer.


Unfortunately there's no such thing in C#. The C# team decided it
wasn't a good idea, although they've said they might revisit that
decision some time.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
Hi,
Static indexers are not available in C#.

"Michel Walsh" <vanderghast@VirusAreFunnierThanSpam> wrote in message
news:uk*************@TK2MSFTNGP12.phx.gbl...
Hi,
Looking for the syntax for a static indexer. For a non static 'access',
the following would do:

public class whatever
{
static Hashtable myHashtable = null;

// ----- here-----
public whatever this[string name]
{
get
{
return (whatever) myHashtable[name] ;
}
}

...
}
Clearly, that does not work prefixing with static,
static public whatever this[string name] {get{return (whatever)
myHashtable[name];} }
since 'this' cannot be used inside a static definition.

Vanderghast, Access MVP


Nov 16 '05 #4
Could you not have a helper class, and then declare a static variable of the
type of this helper class in your main class, the helper class could then
implement the indexer itself (there would only be one instance of it).
"Michel Walsh" wrote:
Hi,
Looking for the syntax for a static indexer. For a non static 'access',
the following would do:

public class whatever
{
static Hashtable myHashtable = null;

// ----- here-----
public whatever this[string name]
{
get
{
return (whatever) myHashtable[name] ;
}
}

...
}
Clearly, that does not work prefixing with static,
static public whatever this[string name] {get{return (whatever)
myHashtable[name];} }
since 'this' cannot be used inside a static definition.

Vanderghast, Access MVP

Nov 16 '05 #5
Hi,
I originally thought to make a static property, Item, and then use
whatever.Item( someName )

but the environment (it should be distribute to other developers) would
have been more "natural", more "cultural" using an indexer. I have to think
if there is not something along the lines you suggest, but my first
impression is that if I found back a "indexing" syntax, it may be with a
little extra complexity... and you know how developers are.... if they find
something is uselessly complex ... :-)
Vanderghast, Access MVP
"Patty O'Dors" <Pa********@discussions.microsoft.com> wrote in message
news:41**********************************@microsof t.com...
Could you not have a helper class, and then declare a static variable of
the
type of this helper class in your main class, the helper class could then
implement the indexer itself (there would only be one instance of it).
"Michel Walsh" wrote:
Hi,
Looking for the syntax for a static indexer. For a non static
'access',
the following would do:

public class whatever
{
static Hashtable myHashtable = null;

// ----- here-----
public whatever this[string name]
{
get
{
return (whatever) myHashtable[name] ;
}
}

...
}
Clearly, that does not work prefixing with static,
static public whatever this[string name] {get{return (whatever)
myHashtable[name];} }
since 'this' cannot be used inside a static definition.

Vanderghast, Access MVP

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ernst Murnleitner | last post by:
Hello Readers, Is there a way that only one class can construct a class A and its inherited classes A2, A3 etc.? I want to construct a class A (and the inherited classes A2, A3 etc.) from a...
3
by: Sam Martin | last post by:
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...
8
by: Bill Cohagan | last post by:
I'm curious as to why C# doesn't support static indexers. Anybody know? Thanks, Bill
7
by: Zytan | last post by:
I know you cannot have a sealed static class, but why not? Why must static classes be left open to inheritance? This article: http://msdn.microsoft.com/msdnmag/issues/03/07/NET/ recommends to...
5
by: Andrus | last post by:
class myclass { public static object this { get { return "Row"; } } } returns error
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.