Skip to content

Commit c810a4a

Browse files
RexJaeschkeBillWagner
authored andcommitted
add indexers and ranges
1 parent 602fd15 commit c810a4a

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

standard/expressions.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3007,7 +3007,7 @@ An *anonymous_method_expression* is one of two ways of defining an anonymous fun
30073007
30083008
### 11.8.1 General
30093009
3010-
The `+`, `-`, `!`, `~`, `++`, `--`, cast, and `await` operators are called the unary operators.
3010+
The `+`, `-`, `!`, `~`, `^`, `++`, `--`, cast, and `await` operators are called the unary operators.
30113011
30123012
```ANTLR
30133013
unary_expression
@@ -3016,6 +3016,7 @@ unary_expression
30163016
| '-' unary_expression
30173017
| '!' unary_expression
30183018
| '~' unary_expression
3019+
| '^' unary_expression
30193020
| pre_increment_expression
30203021
| pre_decrement_expression
30213022
| cast_expression
@@ -3287,7 +3288,10 @@ At run-time, the expression `await t` is evaluated as follows:
32873288
An awaiter’s implementation of the interface methods `INotifyCompletion.OnCompleted` and `ICriticalNotifyCompletion.UnsafeOnCompleted` should cause the delegate `r` to be invoked at most once. Otherwise, the behavior of the enclosing async function is undefined.
32883289

32893290
<<<<<<< HEAD
3291+
<<<<<<< HEAD
3292+
=======
32903293
=======
3294+
>>>>>>> 50008cc (add indexers and ranges)
32913295
## §range-operator Range operator
32923296

32933297
This operator provides a succinct syntax for specifying a (possibly empty) element range suitable for use in denoting a slice of an indexable sequence (§indexable-sequence).
@@ -3305,36 +3309,56 @@ For an operation of the form `s .. e`, binary operator overload resolution ([§1
33053309
System.Range operator ..(System.Index start = 0, System.Index end = ^0);
33063310
```
33073311

3312+
<<<<<<< HEAD
33083313
The left and right operands denote, respectively, a start and end Index. For this operator, an object of (the immutable struct) type `System.Range` is returned that contains those Indexes. If the left operand is omitted, an Index of `0` is used. If the right operand is omitted, an Index of `^0` is used. As such,
33093314

33103315
- `s .. e` is transformed by the implementation to `new System.Range(s, e)`.
33113316
- `s ..` is transformed by the implementation to `new System.Range(s, ^0)` (or to `System.Range.StartAt(s)` if that method exists, is accessible, and is declared as follows: `public static Range StartAt (Index start);`).
33123317
- `.. e` is transformed by the implementation to `new System.Range(0, e)` (or to `System.Range.EndAt(e)` if that method exists, is accessible, and is declared as follows: `public static Range EndAt (Index end);`).
33133318
- `..` is transformed by the implementation to `new System.Range(0, ^0)` (or instead to `System.Range.All` if that property exists, is accessible, and is declared as follows: `public static Range All { get; }`).
3319+
=======
3320+
The left and right operands denote, respectively, a start and end Index. For this operator, an object of (the immutable struct) type `System.Range` is returned that contains those Indexes. If the left operand is omitted, an Index of `0` is used. If the right operand is omitted, an Index of `^0` is used. As such,
3321+
- `s .. e` is transformed by the implementation to `new System.Range(s, e)`.
3322+
- `s ..` is transformed by the implementation to `new System.Range(s, ^0)` (or to ` System.Range.StartAt(s)` if that method exists, is accessible, and is declared as follows: `public static Range StartAt (Index start);`).
3323+
- `.. e` is transformed by the implementation to `new System.Range(0, e)` (or to ` System.Range.EndAt(e)` if that method exists, is accessible, and is declared as follows: `public static Range EndAt (Index end);`).
3324+
- `..` is transformed by the implementation to `new System.Range(0, ^0)` (or instead to ` System.Range.All` if that property exists, is accessible, and is declared as follows: `public static Range All { get; }`).
3325+
>>>>>>> 50008cc (add indexers and ranges)
33143326
33153327
> *Note*: While a Range can be created with a start Index greater than the end Index, any attempt to use that Range to denote a slice from an indexable sequence will result in `System.ArgumentOutOfRangeException`. *end note*
33163328
33173329
Lifted ([§11.4.8](expressions.md#1148-lifted-operators)) forms of the unlifted predefined range operator defined above are also predefined.
33183330

33193331
> *Example*: The following example uses array and string indexable sequences:
3332+
<<<<<<< HEAD
33203333
>
3334+
=======
3335+
>>>>>>> 50008cc (add indexers and ranges)
33213336
> ```csharp
33223337
> string[] seasons = new string[] { "Summer", "Autumn", "Winter", "Spring" };
33233338
> seasons[1..3] // string[2] "Autumn", "Winter"
33243339
> seasons[^2..^1] // string[1] "Winter"
33253340
> seasons[2..] // string[2] "Winter", "Spring"
33263341
> seasons[1..1] // string[0]
3342+
<<<<<<< HEAD
33273343
>
3344+
=======
3345+
>
3346+
>>>>>>> 50008cc (add indexers and ranges)
33283347
> string s2 = "Hello!";
33293348
> Index? startN = 1;
33303349
> Index? endN = ^2;
33313350
> Range? r = startN .. endN;
33323351
> s2[r.Value] // OK: "ell"
33333352
> ```
3353+
<<<<<<< HEAD
33343354
>
33353355
> *end example*
33363356
33373357
>>>>>>> 76616f9 (fix formatting)
3358+
=======
3359+
> *end example*
3360+
3361+
>>>>>>> 50008cc (add indexers and ranges)
33383362
## 11.9 Arithmetic operators
33393363
33403364
### 11.9.1 General
@@ -3343,10 +3367,10 @@ The `*`, `/`, `%`, `+`, and `–` operators are called the arithmetic operators.
33433367
33443368
```ANTLR
33453369
multiplicative_expression
3346-
: unary_expression
3347-
| multiplicative_expression '*' unary_expression
3348-
| multiplicative_expression '/' unary_expression
3349-
| multiplicative_expression '%' unary_expression
3370+
: range_expression
3371+
| multiplicative_expression '*' range_expression
3372+
| multiplicative_expression '/' range_expression
3373+
| multiplicative_expression '%' range_expression
33503374
;
33513375
33523376
additive_expression

0 commit comments

Comments
 (0)