Skip to content

Commit 4d398ce

Browse files
authored
Add example annotation to 3 new examples (#1025)
* Add example annotation * Add example annotation
1 parent 38d9fe5 commit 4d398ce

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Diff for: standard/patterns.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@ A *declaration_pattern* and a *var_pattern* can result in the declaration of a l
2222

2323
Each pattern form defines the set of types for input values that the pattern may be applied to. A pattern `P` is *applicable to* a type `T` if `T` is among the types whose values the pattern may match. It is a compile-time error if a pattern `P` appears in a program to match a pattern input value ([§11.1](patterns.md#111-general)) of type `T` if `P` is not applicable to `T`.
2424

25-
> *Example*: The following example generates a compile-time error because the compile-time type of `v` is `Stream`. A variable of type `Stream` can never have a value that is reference compatible with `string`:
25+
> *Example*: The following example generates a compile-time error because the compile-time type of `v` is `TextReader`. A variable of type `TextReader` can never have a value that is reference-compatible with `string`:
2626
>
27+
> <!-- Example: {template:"standalone-console", name:"PatternFormGen1", expectedWarnings:["CS0184"]} -->
2728
> ```csharp
28-
> Stream v = OpenDataFile(); // compile-time type of 'v' is 'Stream'
29+
> TextReader v = Console.In; // compile-time type of 'v' is 'TextReader'
2930
> if (v is string) // compile-time error
3031
> {
3132
> // code assuming v is a string
3233
> }
3334
> ```
3435
>
35-
> However, the following doesnt generate a compile-time error because the compile-time type of `v` is `object`. A variable of type `object` could have a value that is reference compatible with `string`:
36+
> However, the following doesnt generate a compile-time error because the compile-time type of `v` is `object`. A variable of type `object` could have a value that is reference-compatible with `string`:
3637
>
38+
> <!-- Example: {template:"standalone-console", name:"PatternFormGen2"} -->
3739
> ```csharp
38-
> object v = OpenDataFile();
40+
> object v = Console.In;
3941
> if (v is string s)
4042
> {
4143
> // code assuming v is a string

Diff for: standard/variables.md

+1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ The definite-assignment state of *v* at the beginning of a case’s guard clause
335335
336336
> *Example*: The second 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`.
337337
>
338+
> <!-- Example: {template:"standalone-console-without-using", name:"DefAssignSwitch", expectedWarnings:["CS0162"]} -->
338339
> ```csharp
339340
> bool b;
340341
> switch (1)

0 commit comments

Comments
 (0)