From 2327c2e9b026e1e162d839f61412c51cb44a4e92 Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Wed, 26 Jul 2023 11:19:54 -0400 Subject: [PATCH] annotate-patterns-examples --- standard/patterns.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/standard/patterns.md b/standard/patterns.md index 32513e371..174cdf370 100644 --- a/standard/patterns.md +++ b/standard/patterns.md @@ -66,6 +66,7 @@ It is an error if *type* is a nullable value type. > *Example*: The declaration pattern can be used to test values of nullable types: a value of type `Nullable` (or a boxed `T`) matches a type pattern `T2 id` if the value is non-null and `T2` is `T`, or some base type or interface of `T`. For example, in the code fragment > +> > ```csharp > int? x = 3; > if (x is int v) { /* code using v */ } @@ -98,8 +99,9 @@ Given a *pattern input value* *e* and a constant pattern `P` with converted valu > *Example*: > +> > ```csharp -> public static decimal GetGroupTicketPrice(int visitorCount) +> static decimal GetGroupTicketPrice(int visitorCount) > { > switch (visitorCount) { > case 1: return 12.0m; @@ -107,7 +109,7 @@ Given a *pattern input value* *e* and a constant pattern `P` with converted valu > case 3: return 27.0m; > case 4: return 32.0m; > case 0: return 0.0m; -> default: throw new ArgumentException(…); +> default: throw new ArgumentException(...); > } > } > ``` @@ -160,13 +162,14 @@ A set of patterns `Q` is *exhaustive* for a type `T` if any of the following con > *Example*: > +> > ```csharp > static void M(byte b) > { > switch (b) { > case 0: case 1: case 2: case 3: ... // handle every specific value of byte > break; -> case byte other: // error: the pattern 'byte other' is subsumed by previous cases because the previous cases are exhaustive for byte +> case byte other: // error: the pattern 'byte other' is subsumed by the (exhaustive) previous cases > break; > } > }