AB Vegavænget

A keen indexer_human anatomy may either consist of an accessor looks (§fourteen

A keen indexer_human anatomy may either consist of an accessor looks (§fourteen

The kind of an enthusiastic indexer each of one’s products referenced in the formal_parameter_record should be at the very least due to the fact available as the indexer alone (§seven.5.5).

seven.1) or an expression human body (§14.six.1). eight.3) of your own indexer. The latest accessors indicate the newest executable comments of this understanding and you may writing indexer facets.

An expression body consisting of ” => ” followed by an expression E and a semicolon is exactly equivalent to the block body > , 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 having opening an enthusiastic indexer function ‘s the same as one to to own an array feature, an indexer ability isn’t categorized because the a varying. Thus, that isn’t you’ll be able to to pass through an indexer function given that a great ref otherwise away dispute.

The newest formal_parameter_set of an indexer represent this new trademark (§eight.6) of the indexer. Especially, new signature from an enthusiastic indexer includes the amount and you may items of their authoritative parameters. The new ability kind of and you will brands of one’s authoritative variables commonly part of an enthusiastic indexer’s signature.

When an enthusiastic indexer statement comes with a keen extern modifier, the indexer is said become an outward indexer

Aside from these types of differences, all the legislation discussed inside §14.seven.step 3 and you will §fourteen.seven.4 affect indexer accessors also to assets accessors.

Example: The newest analogy lower than declares an excellent BitArray category you to definitely executes an indexer having opening the person parts from the section variety.

An illustration of the newest BitArray classification eats considerably smaller recollections than simply a matching bool[] (as each worth of the previous takes up only 1 section rather of latter’s one byte ), nevertheless it allows an identical surgery since an effective bool[] .

The following CountPrimes classification spends a BitArray and also the classical “sieve” formula to compute exactly how many primes ranging from 2 and you will good given limit:

Remember that this new syntax to have being able to access parts of the latest BitArray is exactly the same for an effective bool[] . avoid analogy

In an accessor body, accessor_declarations, which shall be enclosed in ” ” tokens, declare the accessors (§14

Example: Another example reveals a good 26?ten grid classification who may have a keen indexer that have a few parameters. The original factor is required to feel an upper- or lowercase letter regarding range Good–Z, additionally the next is required to be a keen integer on the diversity 0–9.