An indexer_human anatomy may either integrate a keen accessor system (§fourteen

Posted on Posted in Maiotaku visitors

An indexer_human anatomy may either integrate a keen accessor system (§fourteen

The type of an enthusiastic indexer and each of your own items referenced about specialized_parameter_record might be at the least since the accessible because the indexer itself (§eight.5.5).

eight.1) or an expression looks (§fourteen.6.1). seven.3) of your indexer. The latest accessors identify new executable statements in the discovering 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.

Even though the sentence structure to have being able to access an indexer feature ‘s the identical to that having a wide range element, a keen indexer element isn’t categorized given that an adjustable. For this reason, this is not it is possible to to take and pass an indexer feature since an effective ref or away argument.

The authoritative_parameter_range of a keen indexer talks of the new trademark (§eight.6) of one’s indexer. Specifically, brand new signature of an indexer contains the quantity and you may versions of the formal variables. The newest element kind of and you can names of your certified details are not section of a keen indexer’s signature.

  • A house is acknowledged by their label, whereas an enthusiastic indexer are acquiesced by their trademark.
  • A property are accessed through a simple_name (§11.seven.4) or an associate_availability (§11.7.6), while a keen indexer element was utilized courtesy an element_access (§11.seven.ten.3).
  • Property are a static member, while an enthusiastic indexer is a situation affiliate.
  • A get accessor away from a house corresponds to a method that have zero parameters, while a get accessor off a keen indexer corresponds to a technique with the exact same authoritative factor checklist maiotaku as indexer.
  • A-flat accessor out of a house represents a method with just one factor entitled worthy of, whereas a-flat accessor regarding an enthusiastic indexer represents a technique with the same specialized factor number given that indexer, also an extra factor titled really worth.
  • It’s an amass-big date error having a keen indexer accessor in order to e title as an enthusiastic indexer factor.
  • In an enthusiastic overriding property statement, the brand new passed on home is accessed utilising the syntax base.P , where P is the property term. Within the an overriding indexer report, brand new inherited indexer are accessed by using the syntax feet[E] , where E is a great comma-split variety of phrases.
  • There isn’t any thought of a keen “automatically then followed indexer”. It’s a blunder getting a non-abstract, non-exterior indexer with semicolon accessors.

Whenever an indexer report boasts an extern modifier, the latest indexer is said to-be an external indexer

Aside from such variations, every statutes defined when you look at the §14.seven.3 and you will §14.7.4 apply to indexer accessors and to assets accessors.

Example: The newest example lower than announces a BitArray classification one executes an indexer for being able to access anyone bits regarding part number.

An instance of this new BitArray classification takes dramatically less memories than a corresponding bool[] (as the for each value of the previous occupies singular portion as an alternative of latter’s you to definitely byte ), nevertheless it permits a comparable operations since the an effective bool[] .

The second CountPrimes class uses a BitArray plus the classical “sieve” algorithm so you’re able to compute exactly how many primes anywhere between 2 and you may good provided limitation:

Observe that the fresh new sentence structure to own being able to access areas of the newest BitArray try precisely the same as for a great bool[] . end example

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

Example: The second example shows a great twenty-six?ten grid classification that has an enthusiastic indexer which have several details. The original parameter is needed to getting an upper- or lowercase letter on the variety A–Z, as well as the 2nd must end up being an integer on the range 0–nine.