Skip to content

Commit e1d7b96

Browse files
RexJaeschkeBillWagner
authored andcommitted
fix formatting
1 parent 31ad881 commit e1d7b96

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
@@ -5117,6 +5117,7 @@ A user-defined type can provide explicit support for indexer access ([§11.7.10.
51175117
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).
51185118
51195119
> *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:
5120+
>
51205121
> ```csharp
51215122
> class BitArray
51225123
> {
@@ -5136,14 +5137,15 @@ A type having an instance indexer taking a single argument of type `System.Index
51365137
> }
51375138
> }
51385139
> ```
5140+
>
51395141
> *end example*
51405142
51415143
#### §indexable-sequence-impl-support-for-index Implicit Index support
51425144
51435145
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:
5144-
- The type is countable [§14.7.1](classes.md#1471-general).
5145-
- 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.
5146-
- 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.
5146+
- The type is countable [§14.7.1](classes.md#1471-general).
5147+
- 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.
5148+
- 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.
51475149
51485150
The provided instance indexer shall have the same get and set members with matching accessibility as the `int` indexer.
51495151
@@ -5158,6 +5160,7 @@ The provided instance indexer shall take the given `System.Index` and use that t
51585160
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).
51595161
51605162
> *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:
5163+
>
51615164
> ```csharp
51625165
> class BitArray
51635166
> {
@@ -5182,15 +5185,16 @@ A type having an instance indexer taking a single argument of type `System.Range
51825185
> }
51835186
> }
51845187
> ```
5188+
>
51855189
> *end example*
51865190
51875191
#### §indexable-sequence-impl-support-for-range Implicit Range support
51885192
51895193
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:
5190-
- The type is countable [§14.7.1](classes.md#1471-general).
5191-
- 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`.
5194+
- The type is countable [§14.7.1](classes.md#1471-general).
5195+
- 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`.
51925196
> *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*
5193-
- 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.
5197+
- 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.
51945198
51955199
The provided instance indexer shall have the same accessibility and return type, including `ref` if present, as `Slice`.
51965200
@@ -5199,6 +5203,7 @@ When the type is indexed with a `System.Range`, the provided instance indexer sh
51995203
> 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.
52005204
52015205
> *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:
5206+
>
52025207
> ```csharp
52035208
> public BitArray Slice(int startIdx, int rangeLength)
52045209
> {
@@ -5211,6 +5216,7 @@ When the type is indexed with a `System.Range`, the provided instance indexer sh
52115216
> return newBitArray;
52125217
> }
52135218
> ```
5219+
>
52145220
*end note*
52155221
52165222
> 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)