Skip to content
Merged
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
13 changes: 13 additions & 0 deletions standard/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,19 @@ The definite-assignment state of *v* on the control flow transfer to a reachable
- If *v* is a pattern variable declared in the *switch_label*: “definitely assigned”.
- Otherwise, the state of *v* is the same as the stat of *v* after *expr*.

> *Example*: The third rule eliminates the need for the compiler to issue an error if an unassigned variable is accessed in unreachable code. The state of *b* is "definitely assigned" in the unreachable switch label `case 2 when b`.
>
> ```csharp
> bool b;
> switch (1)
> {
> case 2 when b: // b is definitely assigned here.
> break;
> }
> ```
>
> *end example*

A consequence of these rules is that a pattern variable declared in a *switch_label* will be “not definitely assigned” in the statements of its switch section if it is not the only reachable switch label in its section.

> *Example*:
Expand Down