An enthusiastic indexer_system can either consist of an enthusiastic accessor muscles (§14

An enthusiastic indexer_system can either consist of an enthusiastic accessor muscles (§14

The sort of an indexer and every of the products referenced regarding authoritative_parameter_listing should be no less than just like the obtainable because the indexer itself (§eight.5.5).

seven.1) or a phrase system (§fourteen.6.1). seven.3) of your own indexer. Brand new accessors establish the executable statements in the understanding and you may writing indexer points.

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 sentence structure for being able to access an indexer feature ‘s the same as that for a selection ability, an indexer function is not categorized once the an adjustable. Ergo, that isn’t you’ll be able to to successfully pass a keen indexer ability as the good ref otherwise aside conflict.

The fresh specialized_parameter_directory of a keen indexer describes the brand new trademark (§eight.6) of your indexer. Particularly, the newest signature out of an indexer includes the number and you may systems of their official details. The new element style of and you may names of your authoritative parameters aren’t part of an enthusiastic indexer’s trademark.

  • Property try identified by their identity, while a keen indexer was acquiesced by the signature.
  • A property try accessed due to an easy_identity (§eleven.7.4) or an associate_accessibility (§eleven.7.6), while an indexer ability is reached as a consequence of a component_accessibility (§11.7.ten.3).
  • A house is a fixed user, whereas a keen indexer is definitely a situation member.
  • A score accessor regarding property represents a strategy that have zero parameters, while a score accessor from a keen indexer corresponds to a technique with similar official factor listing while the indexer.
  • An appartment accessor away from a property represents a strategy having just one parameter named really worth, whereas a flat accessor from an indexer corresponds to a strategy with the same certified factor record since indexer, and additionally an extra factor https://datingranking.net/pl/mature-dating-recenzja/ entitled value.
  • It’s a collect-big date error having an enthusiastic indexer accessor so you’re able to e term given that an enthusiastic indexer factor.
  • Into the a keen overriding assets report, the latest handed down house is accessed utilising the sentence structure feet.P , in which P ‘s the property identity. Inside an overriding indexer declaration, the new handed down indexer try utilized utilising the syntax base[E] , in which Age are an excellent comma-broke up variety of words.
  • There isn’t any idea of an “immediately accompanied indexer”. It is a mistake to own a low-abstract, non-outside indexer with semicolon accessors.

Whenever an indexer report has an extern modifier, the fresh new indexer is considered is an external indexer

Except that these distinctions, all of the legislation defined when you look at the §14.7.step three and §fourteen.eight.cuatro affect indexer accessors also to possessions accessors.

Example: This new analogy less than declares a beneficial BitArray group one to implements an indexer to own opening the person parts about portion selection.

An exemplory case of the fresh new BitArray classification eats considerably smaller memories than simply a corresponding bool[] (because the for every single worth of the previous takes up just one bit instead of your latter’s that byte ), however it it allows a similar businesses since an excellent bool[] .

The next CountPrimes classification uses a good BitArray additionally the ancient “sieve” formula so you can calculate exactly how many primes anywhere between 2 and you will a good provided maximum:

Note that brand new syntax to have accessing areas of this new BitArray is the identical as for good bool[] . stop example

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

Example: Next example shows a good 26?10 grid group who may have an enthusiastic indexer having a few parameters. The initial factor is required to become a higher- otherwise lowercase letter regarding diversity A great–Z, as well as the second is needed to end up being an enthusiastic integer throughout the assortment 0–nine.

Recommended Posts