Skip to content

Commit c49332a

Browse files
RexJaeschkeBillWagner
authored andcommitted
fix formatting
1 parent 86a7ea8 commit c49332a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

standard/classes.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5218,6 +5218,7 @@ A user-defined type can provide explicit support for indexer access ([§11.7.10.
52185218
A type having an instance indexer taking a single argument of type `System.Index`, or a first argument of that type followed by optional arguments, may be indexed as described by [§11.7.10.3](expressions.md#117103-indexer-access).
52195219
52205220
> *Example*: In [§14.9](classes.md#149-indexers), there is an example defining type `BitArray`, which stores bits in an array of `int`. Individual bits are accessed for read/write via an `int` indexer. Adding an `Index` indexer that simply interprets the `Index` argument as an `int`, is simple:
5221+
>
52215222
> ```csharp
52225223
> class BitArray
52235224
> {
@@ -5237,14 +5238,15 @@ A type having an instance indexer taking a single argument of type `System.Index
52375238
> }
52385239
> }
52395240
> ```
5241+
>
52405242
> *end example*
52415243
52425244
#### §indexable-sequence-impl-support-for-index Implicit Index support
52435245
52445246
An implementation shall behave as if it provides an instance indexer member with a single parameter of type `System.Index` for any type that meets the following criteria:
5245-
- The type is countable [§14.7.1](classes.md#1471-general).
5246-
- The type has an accessible instance indexer taking an argument of type `int` as its only argument, or as its first argument with the remaining arguments being optional.
5247-
- The type does not have an accessible instance indexer taking a `System.Index` as its only argument, or as its first argument with the remaining arguments being optional.
5247+
- The type is countable [§14.7.1](classes.md#1471-general).
5248+
- The type has an accessible instance indexer taking an argument of type `int` as its only argument, or as its first argument with the remaining arguments being optional.
5249+
- The type does not have an accessible instance indexer taking a `System.Index` as its only argument, or as its first argument with the remaining arguments being optional.
52485250
52495251
The provided instance indexer shall have the same get and set members with matching accessibility as the `int` indexer.
52505252
@@ -5259,6 +5261,7 @@ The provided instance indexer shall take the given `System.Index` and use that t
52595261
A type having an instance indexer taking a single argument of type `System.Range`, or a first argument of that type followed by optional arguments, may be indexed as described by [§11.7.10.3](expressions.md#117103-indexer-access).
52605262
52615263
> *Example*: In14.9](classes.md#149-indexers), there is an example defining type `BitArray`, which stores bits in an array of `int`. Adding a `Range` indexer that returns a `BitArray` representing the bit slice designated by the Range, is simple:
5264+
>
52625265
> ```csharp
52635266
> class BitArray
52645267
> {
@@ -5283,15 +5286,16 @@ A type having an instance indexer taking a single argument of type `System.Range
52835286
> }
52845287
> }
52855288
> ```
5289+
>
52865290
> *end example*
52875291
52885292
#### §indexable-sequence-impl-support-for-range Implicit Range support
52895293
52905294
An implementation shall behave as if it provides an instance indexer member with a single parameter of type `System.Range` for any type that meets the following criteria:
5291-
- The type is countable [§14.7.1](classes.md#1471-general).
5292-
- The type has an accessible instance method named `Slice` taking two arguments of type `int` as the only arguments. For type `string`, the method `Substring` is used instead of `Slice`.
5295+
- The type is countable [§14.7.1](classes.md#1471-general).
5296+
- The type has an accessible instance method named `Slice` taking two arguments of type `int` as the only arguments. For type `string`, the method `Substring` is used instead of `Slice`.
52935297
> *Note*: As specified in11.7.10.2](expressions.md#117102-array-access), for array access, the method `System.Runtime.CompilerServices.RuntimeHelpers.GetSubArray` is used instead of `Slice`. *end note*
5294-
- The type does not have an accessible instance indexer taking a `System.Range` as its only argument, or as its first argument with the remaining arguments being optional.
5298+
- The type does not have an accessible instance indexer taking a `System.Range` as its only argument, or as its first argument with the remaining arguments being optional.
52955299
52965300
The provided instance indexer shall have the same accessibility and return type, including `ref` if present, as `Slice`.
52975301
@@ -5300,6 +5304,7 @@ When the type is indexed with a `System.Range`, the provided instance indexer sh
53005304
> Note to TG2 reviewers: The MS proposal, sectionImplicit Range support,” provided a very detailed discussion of how to transform a pair of Indexes into a call to `Slice` depending on the form of the range used. Rex did *not* retain this in the final proposal, as he saw no point in doing so. Given a start and end index, it is a simple matter to compute the length **in all cases regardless of range format!**, as he shows in his range indexer implementation inExplicit range supportabove.
53015305
53025306
> *Note*: See §indexable-sequence-expl-support-for-range for an example of an explicitly provided `Range` indexer. If that were not defined, its equivalent would be provided by the implementation, except that the provided indexer would call `Slice` to create and copy the slice. For type `BitArray`, `Slice` might be defined, as follows:
5307+
>
53035308
> ```csharp
53045309
> public BitArray Slice(int startIdx, int rangeLength)
53055310
> {
@@ -5312,6 +5317,7 @@ When the type is indexed with a `System.Range`, the provided instance indexer sh
53125317
> return newBitArray;
53135318
> }
53145319
> ```
5320+
>
53155321
*end note*
53165322
53175323
> Note to TG2 reviewers: Setter: What if anything should we say about implicit and explicit setter for a Range indexer? Certainly, one can define a setter for a user-defined type; however, it is not obvious as to what such a setter would do, especially since it must be used on the left-hand side of assignment taking a right-hand side of the same type as the index returns. In the case of type `BitArray` that would mean something like `ba1[range1] = ba2`, or perhaps `ba1[range1] = ba2[range2]`. As far as Rex could determine, the operations one might like to implement using such a setter are probably best implemented via a named method. In any event, for a compiler-generated Range indexer, attempting to use its setter results in the error messageCS0131 The left-hand side of an assignment must be a variable, property or indexer,” which suggests the generated indexer **has no setter**. If that is the case, we should say that in the previous section.

0 commit comments

Comments
 (0)