Skip to content

Commit 867ba90

Browse files
RexJaeschkeBillWagner
authored andcommitted
add indexers and ranges
1 parent 124fef4 commit 867ba90

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
@@ -3083,7 +3083,7 @@ An *anonymous_method_expression* is one of two ways of defining an anonymous fun
30833083
30843084
### 11.8.1 General
30853085
3086-
The `+`, `-`, `!`, `~`, `++`, `--`, cast, and `await` operators are called the unary operators.
3086+
The `+`, `-`, `!`, `~`, `^`, `++`, `--`, cast, and `await` operators are called the unary operators.
30873087
30883088
```ANTLR
30893089
unary_expression
@@ -3092,6 +3092,7 @@ unary_expression
30923092
| '-' unary_expression
30933093
| '!' unary_expression
30943094
| '~' unary_expression
3095+
| '^' unary_expression
30953096
| pre_increment_expression
30963097
| pre_decrement_expression
30973098
| cast_expression
@@ -3363,7 +3364,10 @@ At run-time, the expression `await t` is evaluated as follows:
33633364
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.
33643365

33653366
<<<<<<< HEAD
3367+
<<<<<<< HEAD
3368+
=======
33663369
=======
3370+
>>>>>>> 50008cc (add indexers and ranges)
33673371
## §range-operator Range operator
33683372

33693373
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).
@@ -3381,36 +3385,56 @@ For an operation of the form `s .. e`, binary operator overload resolution ([§1
33813385
System.Range operator ..(System.Index start = 0, System.Index end = ^0);
33823386
```
33833387

3388+
<<<<<<< HEAD
33843389
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,
33853390

33863391
- `s .. e` is transformed by the implementation to `new System.Range(s, e)`.
33873392
- `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);`).
33883393
- `.. 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);`).
33893394
- `..` 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; }`).
3395+
=======
3396+
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,
3397+
- `s .. e` is transformed by the implementation to `new System.Range(s, e)`.
3398+
- `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);`).
3399+
- `.. 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);`).
3400+
- `..` 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; }`).
3401+
>>>>>>> 50008cc (add indexers and ranges)
33903402
33913403
> *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*
33923404
33933405
Lifted ([§11.4.8](expressions.md#1148-lifted-operators)) forms of the unlifted predefined range operator defined above are also predefined.
33943406

33953407
> *Example*: The following example uses array and string indexable sequences:
3408+
<<<<<<< HEAD
33963409
>
3410+
=======
3411+
>>>>>>> 50008cc (add indexers and ranges)
33973412
> ```csharp
33983413
> string[] seasons = new string[] { "Summer", "Autumn", "Winter", "Spring" };
33993414
> seasons[1..3] // string[2] "Autumn", "Winter"
34003415
> seasons[^2..^1] // string[1] "Winter"
34013416
> seasons[2..] // string[2] "Winter", "Spring"
34023417
> seasons[1..1] // string[0]
3418+
<<<<<<< HEAD
34033419
>
3420+
=======
3421+
>
3422+
>>>>>>> 50008cc (add indexers and ranges)
34043423
> string s2 = "Hello!";
34053424
> Index? startN = 1;
34063425
> Index? endN = ^2;
34073426
> Range? r = startN .. endN;
34083427
> s2[r.Value] // OK: "ell"
34093428
> ```
3429+
<<<<<<< HEAD
34103430
>
34113431
> *end example*
34123432
34133433
>>>>>>> 76616f9 (fix formatting)
3434+
=======
3435+
> *end example*
3436+
3437+
>>>>>>> 50008cc (add indexers and ranges)
34143438
## 11.9 Arithmetic operators
34153439
34163440
### 11.9.1 General
@@ -3419,10 +3443,10 @@ The `*`, `/`, `%`, `+`, and `–` operators are called the arithmetic operators.
34193443
34203444
```ANTLR
34213445
multiplicative_expression
3422-
: unary_expression
3423-
| multiplicative_expression '*' unary_expression
3424-
| multiplicative_expression '/' unary_expression
3425-
| multiplicative_expression '%' unary_expression
3446+
: range_expression
3447+
| multiplicative_expression '*' range_expression
3448+
| multiplicative_expression '/' range_expression
3449+
| multiplicative_expression '%' range_expression
34263450
;
34273451
34283452
additive_expression

0 commit comments

Comments
 (0)