An enthusiastic indexer_looks may either add an enthusiastic accessor human anatomy (§14

An enthusiastic indexer_looks may either add an enthusiastic accessor human anatomy (§14

The sort of a keen indexer and every of versions referenced in the specialized_parameter_number should be at least as the available since the indexer by itself (§eight.5.5).

7.1) otherwise an expression human anatomy (§fourteen.six.1). eight.3) of indexer. The newest accessors identify the fresh executable statements with the understanding and you will creating indexer elements.

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.

As the sentence structure to possess opening a keen indexer function ‘s the just like one to getting an array ability, an indexer feature is not classified given that a variable. Hence, this is simply not you’ll to successfully pass an enthusiastic indexer feature while the an excellent ref or away argument.

Brand new specialized_parameter_range of an enthusiastic indexer represent the new signature (§eight.6) of indexer. Specifically, the newest signature off an enthusiastic indexer includes the amount and you can versions of their certified variables. The new feature type of and you will brands of one’s certified parameters commonly section of a keen indexer’s signature.

  • A property try acquiesced by their label, whereas a keen indexer is actually recognized by the signature.
  • Property is accessed owing to a simple_label (§eleven.seven chatstep.4) otherwise a member_access (§11.eight.6), while a keen indexer feature are reached using an element_accessibility (§eleven.seven.10.3).
  • Property will likely be a static affiliate, whereas a keen indexer is definitely a case member.
  • A score accessor from a house represents a technique which have zero variables, while a score accessor regarding an enthusiastic indexer represents a strategy with the same authoritative factor listing just like the indexer.
  • An appartment accessor out-of a property represents a technique that have an individual parameter entitled really worth, while an appartment accessor out-of a keen indexer represents a method with the same certified factor record because the indexer, also an additional factor titled really worth.
  • It’s an amass-big date mistake for an enthusiastic indexer accessor so you’re able to elizabeth identity because the an indexer factor.
  • For the an enthusiastic overriding assets statement, the brand new inherited property is reached utilising the sentence structure foot.P , in which P is the property name. Inside an overriding indexer declaration, the fresh handed down indexer are accessed making use of the sentence structure ft[E] , in which Elizabeth is actually good comma-split up directory of terms.
  • There’s absolutely no notion of a keen «instantly observed indexer». It’s a blunder to own a low-conceptual, non-exterior indexer that have semicolon accessors.

Whenever a keen indexer statement includes a keen extern modifier, the latest indexer is alleged to be an external indexer

Other than this type of differences, all laws and regulations discussed for the §fourteen.7.3 and you will §fourteen.seven.4 apply to indexer accessors also to possessions accessors.

Example: New example below declares an effective BitArray category that tools an enthusiastic indexer to have being able to access anyone bits on the bit array.

An exemplory instance of new BitArray group takes considerably reduced recollections than just a matching bool[] (while the for every single value of the former occupies just one piece instead of the latter’s that byte ), however it it allows a similar operations due to the fact an excellent bool[] .

The next CountPrimes classification uses a good BitArray in addition to traditional «sieve» formula so you’re able to calculate what number of primes anywhere between dos and you will a good provided limitation:

Remember that this new syntax to possess opening areas of the new BitArray try the same for a bool[] . end analogy

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

Example: The next example shows a 26?10 grid group who’s got a keen indexer that have one or two parameters. The original factor is required to become an upper- otherwise lowercase letter regarding assortment Good–Z, and 2nd is required to getting an enthusiastic integer regarding the diversity 0–nine.

Publicado en chatstep-inceleme visitors