static indexer

  • Thread starter Thread starter Andrus
  • Start date Start date
A

Andrus

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.
 
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
 
Peter Bromberg said:
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).)
 
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.
 
Andrus said:
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
 
Back
Top