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 5 3760
Michel Walsh <vanderghast@Vi rusAreFunnierTh anSpam> 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.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Hi,
Thanks for the info.
Vanderghast, Access MVP
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com... Michel Walsh <vanderghast@Vi rusAreFunnierTh anSpam> 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.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Hi,
Static indexers are not available in C#.
"Michel Walsh" <vanderghast@Vi rusAreFunnierTh anSpam> wrote in message
news:uk******** *****@TK2MSFTNG P12.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
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
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********@dis cussions.micros oft.com> wrote in message
news:41******** *************** ***********@mic rosoft.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
(factory) class Fa.
I wanted to make that only F can call
new A
|
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
like to define a static indexer so that the following syntax is possible
e.g.
ns.RegularExpressions
I've got a static method that does this, but i want to know if it's possible
|
by: Bill Cohagan |
last post by:
I'm curious as to why C# doesn't support static indexers. Anybody know?
Thanks,
Bill
|
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 place DLL imports into a sealed class, with a private
constructor to prevent instantiation (see Figure 1 at the very top):
http://msdn.microsoft.com/msdnmag/issues/03/07/NET/default.aspx?loc=&fig=true#fig1
Why not just make a static class to...
|
by: Andrus |
last post by:
class myclass {
public static object this {
get {
return "Row";
}
}
}
returns error
| |
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |