views:

94

answers:

4

I have looked over the MSDN site and I haven't been able to find C# indexer's documentation of a specific class

For instance, I want to find HttpRequest's public string this[string key] documentation

Where can i find it?

+1  A: 

How about this:

http://msdn.microsoft.com/en-us/library/system.web.httprequest.item.aspx

Gets the specified object from the QueryString, Form, Cookies, or ServerVariables collections.

public string this[string key ] { get; }
Anna Lear
+1  A: 

Looking at the documentation for VB which doesn't have indexers, the property for HttpRequest is Item. If you change the code example to C# it shows the indexer syntax.

Equiso
+3  A: 

Since vb.Net doesn't have indexers, there is usually a specific named property which is mapped to the indexer in C#. For many classes (including HttpRequest), it's Item

http://msdn.microsoft.com/en-us/library/system.web.httprequest.item.aspx

James Curran
It's always named "Item", isn't it? I think that it must be a special name, since in C# you cannot create a class that has both an Item property and an indexer property. You'll get the (arguably confusing) error on the indexer property that "the type '...' already contains a definition for 'Item'".
Dr. Wily's Apprentice
It's not always "Item" although nearly so. I do recall one class where it was "Cell", but I can't find it now. (I'm also not sure how used name it something different)
James Curran
Holy cow, you're right! Apparently you can stick the `System.Runtime.CompilerServices.CSharp.IndexerName` attribute on your indexer to specify a name other than "Item". (http://msdn.microsoft.com/en-us/library/2549tw02%28VS.71%29.aspx)
Dr. Wily's Apprentice
Sorry, the attribute is actually `System.Runtime.CompilerServices.IndexerName`. Here's a link to more current documentation: http://msdn.microsoft.com/en-us/library/2549tw02.aspx
Dr. Wily's Apprentice
Thanks to all, I never even imagined you could call it whatever you want. Since it was part of the framework it should have been better if the name was fixed like Enumerable for the foreach statement.
Carlos Muñoz
A: 

Get Reflector from Red Gate and look at the details of the method/property to really understand what is going on.

jalexiou