The kind of an indexer each of your sizes referenced on authoritative_parameter_record will be no less than as the accessible once the indexer itself (§7.5.5).
eight.1) or a term system (§fourteen.6.1). 7.3) of indexer. The fresh accessors establish the brand new executable statements associated with understanding and you can composing indexer issues.
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.
While the syntax to own opening a keen indexer element is the identical to that for an array function, a keen indexer ability is not categorized given that a changeable. For this reason, this isn’t possible to successfully pass an indexer element as the a ref or out argument.
New formal_parameter_a number parship of an indexer defines new signature (§7.6) of your own indexer. Particularly, this new signature of an indexer include the amount and you may models of the authoritative parameters. New ability sort of and you will brands of your official details commonly section of a keen indexer’s signature.
- A home is actually acquiesced by its term, while a keen indexer are identified by its trademark.
- A home was reached due to a straightforward_name (§eleven.7.4) or a member_access (§11.7.6), whereas an enthusiastic indexer ability are accessed owing to a feature_availableness (§eleven.seven.ten.3).
- A property will be a static associate, whereas an indexer is obviously a situation affiliate.
- A score accessor away from a house corresponds to a technique that have zero variables, whereas a get accessor out-of an indexer corresponds to a strategy with the exact same certified factor listing given that indexer.
- A-flat accessor from a home represents a technique that have one factor named worth, whereas a set accessor off an enthusiastic indexer corresponds to a method with the same authoritative factor checklist once the indexer, including an extra parameter entitled worth.
- It’s an accumulate-big date mistake having a keen indexer accessor in order to age title since an indexer factor.
- In a keen overriding property statement, the new handed down house is reached with the sentence structure feet.P , in which P is the property term. Into the an overriding indexer statement, brand new handed down indexer is reached utilizing the sentence structure feet[E] , where E was an effective comma-separated range of terms.
- There is absolutely no concept of an enthusiastic “instantly followed indexer”. It is a blunder having a non-abstract, non-additional indexer which have semicolon accessors.
When a keen indexer statement boasts a keen extern modifier, brand new indexer is alleged are an external indexer
Besides this type of differences, the legislation outlined when you look at the §14.seven.step three and you will §fourteen.7.4 affect indexer accessors as well as to property accessors.
Example: The latest analogy less than announces an excellent BitArray group one tools an indexer having accessing the person parts about piece selection.
An example of the latest BitArray classification consumes dramatically faster thoughts than a corresponding bool (while the per worth of the previous uses up just one portion alternatively of the latter’s you to definitely byte ), nevertheless it allows an identical businesses once the an excellent bool .
The next CountPrimes class spends an effective BitArray as well as the classical “sieve” formula to calculate what number of primes between 2 and you will an excellent considering restrict:
Keep in mind that new sentence structure to have accessing elements of the newest BitArray is actually the identical for a great bool . avoid analogy
In an accessor body, accessor_declarations, which shall be enclosed in ” < ">” tokens, declare the accessors (§14
Example: The second example shows a twenty six?ten grid class who may have an indexer which have several parameters. The original parameter is needed to be a higher- or lowercase letter regarding the variety An excellent–Z, and next must end up being an enthusiastic integer in the diversity 0–9.