An enthusiastic indexer_human body can either add an enthusiastic accessor looks (§fourteen

The type of an enthusiastic indexer and each of your own models referenced throughout the authoritative_parameter_number is at the very least since obtainable as the indexer by itself (§7.5.5).

eight.1) or an expression human anatomy (§fourteen.six.1). seven.3) of the indexer. This new accessors establish the fresh executable comments on the discovering and you may 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 sentence structure having accessing an indexer element is the just like one having an array function, an indexer ability is not categorized just like the a varying. For this reason, this isn’t you’ll be able to to successfully pass an indexer function given that good ref otherwise aside dispute.

The fresh new specialized_parameter_listing of a keen indexer describes the brand new trademark (§7.6) of the indexer. Especially, the signature of an indexer include the number and you can sizes of the formal parameters. Brand new feature particular and names of your formal variables are not element of an indexer’s signature.

  • A house is actually acquiesced by its name, while an indexer is recognized by their trademark.
  • Property is actually mocospace utilized thanks to a straightforward_term (§11.eight.4) otherwise a member_supply (§11.eight.6), whereas a keen indexer ability is reached due to an element_accessibility (§
  • A property should be a static member, while a keen indexer is obviously a case representative.
  • A score accessor out-of property corresponds to a strategy with no details, whereas a get accessor out-of an enthusiastic indexer represents a strategy with similar certified parameter record as indexer.
  • A-flat accessor from a house represents a strategy having an individual factor titled really worth, whereas a-flat accessor off an indexer corresponds to a method with similar formal factor record given that indexer, also an additional parameter titled worth.
  • It’s a secure-big date error to possess an enthusiastic indexer accessor to age term since the an indexer parameter.
  • For the a keen overriding property declaration, the new passed on house is accessed by using the syntax foot.P , where P ‘s the assets term. From inside the an overriding indexer report, new passed on indexer are accessed utilizing the syntax feet[E] , in which E try good comma-separated variety of terms.
  • There is absolutely no concept of a keen «instantly implemented indexer». It’s a blunder to have a low-abstract, non-exterior indexer with semicolon accessors.

When an enthusiastic indexer statement boasts a keen extern modifier, the fresh indexer is alleged becoming an external indexer

Apart from these types of variations, most of the statutes defined inside §14.eight.step three and you may § apply at indexer accessors and also to assets accessors.

Example: The latest example lower than declares a BitArray class one to implements an enthusiastic indexer having being able to access anyone bits from the section assortment.

An example of the brand new BitArray group consumes considerably reduced memory than simply a corresponding bool[] (because the for every single value of the former takes up just one bit instead of one’s latter’s one byte ), however it it allows an equivalent operations as the a beneficial bool[] .

Next CountPrimes class uses a beneficial BitArray plus the traditional «sieve» algorithm in order to calculate exactly how many primes between 2 and you may an excellent given restriction:

Remember that new sentence structure to own being able to access components of the latest BitArray is actually identical in terms of a good bool[] . avoid analogy

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

Example: The following analogy suggests an effective twenty-six?10 grid category that has an enthusiastic indexer which have one or two details. The original parameter is required to feel a top- otherwise lowercase page on range An excellent–Z, and also the next is needed to become an integer on variety 0–nine.