문제

The C# docs have a page on indexers, which appears to use "indexer" to refer to the construct required to enable instances of a class to be accessed via square bracket notation.

Indexers allow instances of a class or struct to be indexed just like arrays.

// Define the indexer to allow client code to use [] notation.
public T this[int i]
{
   get { return arr[i]; }
   set { arr[i] = value; }
}

On the other hand, the pandas docs use "indexer" in several ways. Firstly, DataFrame attributes such as ix, loc and iloc that exist to enable different kinds of indexing operation on DataFrame instances are called indexers themselves. For example, see the first line in the docs for ix:

A primarily label-location based indexer, with integer position fallback.

Yet "indexer" is also used elsewhere to refer to the argument passed within square brackets:

.iloc is strictly integer position based (from 0 to length-1 of the axis), will raise IndexError if an indexer is requested and it is out-of-bounds, except slice indexers which allow out-of-bounds indexing.

Both of these uses are also found in the source code, so this is consistent.

The Wikipedia page for indexers does not help distinguish between all of the examples above, although the page in general does seem biased to the usage in the C# docs.

In object-oriented programming, an indexer allows instances of a particular class or struct to be indexed just like arrays.

What is an indexer? Are all of these usages correct? What am I missing?

도움이 되었습니까?

해결책

There is no universally accepted definition of "indexer".

Each language/framework might overload the name for its own use.

As you point out, it usually has something to do with the ability to "index" a thing. But that is as far as any similarity between its uses go.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 softwareengineering.stackexchange
scroll top