The sort of a keen indexer and each of one’s systems referenced on specialized_parameter_checklist is going to be at the very least since available while the indexer in itself (§7.5.5).
7.1) or an expression muscles (§14.6.1). seven.3) of indexer. The newest accessors identify the latest executable statements for the discovering and you can writing indexer issue.
An expression body consisting of ” => ” followed by an expression E and a semicolon is exactly equivalent to the block body < get>> , and can therefore only be used to specify getter-only indexers where the result of the getter is given by a single expression.
Although the sentence structure getting being able to access an indexer element ‘s the same as one to have a wide range ability, an indexer function isn’t categorized because the a changeable. For this reason, that isn’t you are able to to take and pass an enthusiastic indexer ability because a beneficial ref otherwise out conflict.
The official_parameter_listing of an enthusiastic indexer talks of the fresh new trademark (§seven.6) of your indexer. Particularly, new trademark off an enthusiastic indexer contains the amount and you can products of its authoritative variables. Brand new feature sort of and you will brands of your certified parameters are not part of a keen indexer’s signature.
- A property was acquiesced by their name, whereas an indexer is actually identified by its trademark.
- A home is reached thanks to an easy_label (§eleven.7.4) or a member_supply (§11.eight.6), while a keen indexer ability is actually accessed due to an element_access (§11.7.ten.3).
- A property shall be a static user, whereas an enthusiastic indexer is a case user.
- A score accessor away from a house corresponds to a strategy which have zero details, while a get accessor out-of an enthusiastic indexer corresponds to a strategy with similar specialized parameter number as the indexer.
- A set accessor regarding a property corresponds to a method which have one factor called value, whereas a-flat accessor from an indexer represents a method with similar official factor list given that indexer, together with an additional factor named well worth.
- It is a harvest-go out error getting a keen indexer accessor in order to age identity because the an enthusiastic indexer parameter.
- Into the an overriding https://datingranking.net/pl/thaifriendly-recenzja/ possessions report, the newest passed on home is utilized making use of the syntax feet.P , where P ‘s the possessions term. During the a keen overriding indexer report, the fresh inherited indexer is actually utilized utilising the syntax ft[E] , where Elizabeth was a good comma-split up listing of expressions.
- There is no concept of a keen “automatically implemented indexer”. It’s a mistake to have a non-abstract, non-additional indexer having semicolon accessors.
Whenever a keen indexer statement comes with an extern modifier, the fresh indexer is claimed to get an external indexer
Aside from these types of distinctions, most of the laws and regulations defined inside the §14.eight.3 and you will §fourteen.7.cuatro apply at indexer accessors as well as assets accessors.
Example: The brand new analogy below announces a beneficial BitArray class that implements a keen indexer for opening the person bits throughout the section array.
An example of the fresh BitArray group consumes dramatically shorter thoughts than a matching bool[] (because for each and every worth of the former takes up only 1 bit rather of your own latter’s you to definitely byte ), however it it allows an identical businesses because a good bool[] .
Next CountPrimes category spends a BitArray additionally the traditional “sieve” formula to help you compute the number of primes ranging from dos and you can an effective given restrict:
Remember that the fresh syntax getting accessing components of brand new BitArray try the identical in terms of an excellent bool[] . avoid example
In an accessor body, accessor_declarations, which shall be enclosed in ” < ">” tokens, declare the accessors (§14
Example: The following example shows an excellent 26?10 grid group having an enthusiastic indexer that have one or two variables. The original factor must getting a top- or lowercase page in the assortment An excellent–Z, and the second is needed to getting an integer in the range 0–9.