473,406 Members | 2,745 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,406 software developers and data experts.

static indexer

class myclass {

public static object this[string index] {
get {
return "Row[index]";
}
}
}

returns error

modifier static is not allowed for this item.

How to use static indexer ?

Andrus.
Jun 30 '07 #1
5 1876
>returns error
>
modifier static is not allowed for this item.

How to use static indexer ?
You can't, that's what the error message is telling you.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 30 '07 #2
What Mattias is telling you is that an indexer requires "this" - which is an
instance reference. Static = "no instance".
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com

"Andrus" wrote:
class myclass {

public static object this[string index] {
get {
return "Row[index]";
}
}
}

returns error

modifier static is not allowed for this item.

How to use static indexer ?

Andrus.
Jun 30 '07 #3
Peter Bromberg [C# MVP] <pb*******@yahoo.yabbadabbadoo.comwrote:
What Mattias is telling you is that an indexer requires "this" - which is an
instance reference. Static = "no instance".
Of course, that's just a matter of syntax - supporting static indexers
is perfectly feasible technically, it just isn't supported in C#.

(In some cases it would make a lot of sense, eg: Encoding[encodingName]
instead of Encoding.GetEncoding(encodingName).)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 30 '07 #4
Of course, that's just a matter of syntax - supporting static indexers
is perfectly feasible technically, it just isn't supported in C#.

(In some cases it would make a lot of sense, eg: Encoding[encodingName]
instead of Encoding.GetEncoding(encodingName).)
I use static class like Invoice in RDL report expressions.

Currently I need to write in all report expressions

Invoice.Get("amount", Fields!InvoiceId.Value)

This makes expressions complicated.
I want to use indexer to simplify this like

Invoice["amount", Fields!InvoiceId.Value]

How to fix this C# bug ?

Andrus.
Jul 1 '07 #5
Andrus <ko********@hot.eewrote:
Of course, that's just a matter of syntax - supporting static indexers
is perfectly feasible technically, it just isn't supported in C#.

(In some cases it would make a lot of sense, eg: Encoding[encodingName]
instead of Encoding.GetEncoding(encodingName).)

I use static class like Invoice in RDL report expressions.

Currently I need to write in all report expressions

Invoice.Get("amount", Fields!InvoiceId.Value)

This makes expressions complicated.
I want to use indexer to simplify this like

Invoice["amount", Fields!InvoiceId.Value]

How to fix this C# bug ?
It's not a bug, it's a design decision with pros and cons. We may both
agree that it would be a nice feature to have, but that doesn't make
the current state "buggy".

However, the way to change things is to post a feature request on
http://connect.microsoft.com

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 1 '07 #6

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

Similar topics

14
by: Nikhil Patel | last post by:
Hi all, Is it possible to have more than one indexer in a class. If not, are there any good alternative ways to achieve similar functionality. Thanks... -Nikhil
12
by: Sergey Klementiev | last post by:
Why it's impossible to have a static indexer in C#?
7
by: Oren | last post by:
hi I have created a class with a simple indexer what is the syntax for adding the function "Remove" ... myClass.colors=Color.Black; // WORKS O myClass.colors.Remove(); // ?? .......
5
by: Michel Walsh | last post by:
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;
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...
7
by: Steph | last post by:
I'm learning C#. I need to implement an indexer using an array list. I have the following code and I'm getting an error "Inconsistent accessibility: indexer return type CRegs is less accessible...
8
by: Bill Cohagan | last post by:
I'm curious as to why C# doesn't support static indexers. Anybody know? Thanks, Bill
3
by: Nash Alexx | last post by:
Hello! I am quite new to C#, and one concept that really gives me a headache is "indexer". I have gone through the MSDN examples, and, at some level know how to use indexers. But, the thing is I...
9
by: LamSoft | last post by:
Class B { public B() {} } Class A : B { public static string ABC = "myABC"; public A() {} }
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.