Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions standard/statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,8 @@ is semantically equivalent to:
}
```

except that no copy of `x` is made when `GetEnumerator()` is called.

The variable `e` is not visible to or accessible to the expression `x` or the embedded statement or any other source code of the program. The variable `v` is read-only in the embedded statement. If there is not an explicit conversion ([§10.3](conversions.md#103-explicit-conversions)) from `T` (the iteration type) to `V` (the *local_variable_type* in the `foreach` statement), an error is produced and no further steps are taken.

When the iteration variable is a reference variable ([§9.7](variables.md#97-reference-variables-and-returns)), a `foreach` statement of the form
Expand Down Expand Up @@ -1225,6 +1227,8 @@ is semantically equivalent to:
}
```

except that no copy of `x` is made when `GetEnumerator()` is called.

The variable `e` is not visible or accessible to the expression `x` or the embedded statement or any other source code of the program. The reference variable `v` is read-write in the embedded statement, but `v` shall not be ref-reassigned ([§12.23.4](expressions.md#12234-ref-assignment)). If there is not an identity conversion ([§10.2.2](conversions.md#1022-identity-conversion)) from `T` (the iteration type) to `V` (the *local_variable_type* in the `foreach` statement), an error is produced and no further steps are taken.

A `foreach` statement of the form `foreach (ref readonly V v in x) «embedded_statement»` has a similar equivalent form, but the reference variable `v` is `ref readonly` in the embedded statement, and therefore cannot be ref-reassigned or reassigned.
Expand Down Expand Up @@ -1473,6 +1477,8 @@ is semantically equivalent to:
}
```

except that no copy of `x` is made when `GetEnumerator()` is called.

This follows the behavior of synchronous foreach ([§13.9.5.2](statements.md#13952-synchronous-foreach)), differing by replacing the declaration and initialisation of a single iteration variable with a *deconstructing_assignment* in which the *deconstructor* contains the iteration-variable declarations: each *declaration_expression* other than a discard declares one iteration variable, and each discard ([§9.2.9.2](variables.md#9292-discards)) declares none:

- `C` and `E` are determined as for synchronous foreach
Expand Down
Loading