Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference an indexer member of a class in C# comments

In order to reference a member of a class in XML comments/documentation, you have to use the following tag:

<see cref="member"/>

It is better explained here.

How do you reference an indexer?

I mean, a member like this one:

internal object this[ int index ] {
    ...
}

Thanks in advance.

like image 821
Auron Avatar asked Dec 04 '08 16:12

Auron


People also ask

What is indexers in C# with example?

An indexer is a special type of property that allows a class or a structure to be accessed like an array for its internal collection. C# allows us to define custom indexers, generic indexers, and also overload indexers. An indexer can be defined the same way as property with this keyword and square brackets [] .

Which keyword is used to declare indexers?

The this keyword is used to define the indexer. The value keyword is used to define the value being assigned by the set accessor.

CAN interface have indexers like class?

Like a class, Interface can have methods, properties, events, and indexers as its members.

Can a class have multiple indexers?

In C#, we can have multiple indexers in a single class. To overload an indexer, declare it with multiple parameters and each parameter should have a different data type. Indexers are overloaded by passing 2 different types of parameters. It is quite similar to method overloading.


4 Answers

I've had the same question, but with a generic Dictionary.Item(TKey) property. The answer by leppie

<see cref="P:System.Collections.ArrayList.Item(System.Int32)" />

and the additional link by ICR (unfortunately I cannot find the "mscorlib.xml")

MSDN: Processing the XML File (C# Programming Guide)

helped me out.

But the answer by user492238
(I know, I should directly comment his answer. But since I am new and this is my first post, please go easy on me, because I am not allowed to comment due to my low reputation.)

<seealso cref="M:My.Namespace.Class1.Get{T}(System.String)"/>
<seealso cref="M:My.Namespace.Class1.Get&lt;T>(System.String)"/>

resulted only in plain, black text, whereby only the seconds shows tag signs <> as given "hard-coded".

I found the solution on the MSDN page to use backticks (`) for generics and got a full ("colory") references to the class and property within my XMLDoc:

    <see cref="P:System.Collections.Generic.Dictionary`2.Item(`0)" />
Dictionary<TKey, TValue>.this[TKey]
like image 113
Qny Avatar answered Sep 23 '22 03:09

Qny


<see cref="P:System.Collections.ArrayList.Item(System.Int32)" />
like image 35
leppie Avatar answered Sep 21 '22 03:09

leppie


<see cref="this[int]" />
like image 31
jyoung Avatar answered Sep 22 '22 03:09

jyoung


<see cref="ReadOnlyCollection{T}.this[int]" />

as proposed here.

like image 43
tm1 Avatar answered Sep 21 '22 03:09

tm1