An interviewer asked me this question, I was puzzled by this term because I understand what a "static" member is and I'm familiar with the concept of an "index" but what exactly is meant static indexer
? I did some searching of my own but was unable to find a satisfactory definition.
Asked
Active
Viewed 4,298 times
3

Kittoes0124
- 4,930
- 3
- 26
- 47

BreakHead
- 10,480
- 36
- 112
- 165
-
1I'd say it's an indexer that is static, but I understand your confusion. Not sure if that's what your recruiter would've wanted to hear :S – Nolonar Apr 18 '13 at 08:14
-
1@hangy I saw that question too, but still it didn't answer the question what I am expecting?? the question posted was 'Why Static indexers is not allowed in C#'?? but my question is 'what is static indexer'? :( – BreakHead Apr 18 '13 at 08:17
-
1I don't know if you are aware that there is no stattic indexer in c#. It could be a trick question from your interviewer or he may be trying to size up of your understanding of static access level or indexers. – Edper Apr 18 '13 at 08:25
1 Answers
1
static indexer is Not Possible in C#
Indexer semantics require the 'this' keyword which defines the block of code as an indexer, and is a also reference to the current instance of a class. Since a static indexer would have no such reference, it stands to reason that you can't define an indexer as static. That's just my personal interpretation, there may be a bigger picture than that.
However, if you have a special need, indexers are just a convenience - you can accomplish what you want to do the old fashioned way through methods.
The fact of the matter is, however, that indexers can't be defined as static.

Sagar Hirapara
- 1,677
- 13
- 24
-
this is just an indication to compiler that this member is a class indexer, you could as well use mars for that place holder and it would serve the same purpose. – Tanveer Badar Jun 24 '14 at 13:16